using System;
using System.Collections.Generic;
using System.Linq;

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {
            /* 
            var N = long.Parse(Console.ReadLine());
            var cities = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var brave = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            */

            //Console.WriteLine(outer);
            //SLV(new long[]{13, 3});
            SLV(Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse));
            //SLV(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
            //SLV(Console.ReadLine());
            Console.ReadKey();
        }

        public static void SLV(long[] input){


            
            var deadLine = input[1];
            var N = input[0];
            
            var list = new List<int>[deadLine+1];
            for(int i = 0; i <= deadLine; i++){
                list[i] = new List<int>();
            }

            int[] x;


            for(int i = 0; i < N; i++){
                x = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                if(x[0] > deadLine) continue;
                list[int.Parse(x[0].ToString())].Add(x[1]);
            }

            var count = new int[100100];
            count[0] = int.MaxValue;

            var currentV = 0;
            long value = 0;

            for(int i = 1; i <= deadLine; i++){
                foreach(var tgt in list[i]){
                    count[tgt]++;
                    currentV = Math.Max(currentV, tgt);
                }

                if(count[currentV] == 0){
                    while(count[currentV] == 0) currentV--;
                }
                value += currentV;
                count[currentV]--;

            }

            Console.WriteLine(value);
            
        }

        private class work : IComparable<work>{

            public long profitDay{get;set;}
            public long profit{get;set;}

            public work(long x, long y){
                this.profitDay = x;
                this.profit = y;
            }

            public int CompareTo(work input){
                if(this.profit > input.profit) return -1;
                if(this.profit < input.profit) return 1;
                if(this.profitDay == input.profitDay) return 0;

                return this.profitDay < input.profitDay ? -1 : 1;
            }

        }




        public static long modder(){
            return (long)Math.Pow(10,9) + 7;
        }

        public static long GCD(long n, long m){
            
            if(m % n == 0) return n;
            else return GCD(m%n, n);

        }

        public static long LCD(long n, long m){

            return m * n / GCD(n,m);
        }

        
        // いやなんか違うけどねこれ
        public static long lower_bound(long[] array, long input){
            var left = 0;
            var right = array.Length-1;
            var mid =0;
            while(right >= left){
                mid = left + (right - left)/2;
                if(array[mid] == input){
                    return mid;
                }
                if(array[mid] > input){
                    right = mid-1;
                }else{
                    left = mid+1;
                }
            }
    
            return right;
        }

        
        class UfTree{
            public long[] parents{get;set;}
            public long[] size{get;set;} //sizeはrootのみが最新のものを保持する
    
            public UfTree(long n){
                parents = new long[n];
                size = new long[n];
                for(long i = 0; i < n; i++){
                    parents[i] = i;
                    size[i] = 1;
                } 
            }
    
            public long getRoot(long x){
                if(parents[x] == x){
                    return x;
                }else{
                    parents[x] = getRoot(parents[x]);
                    return parents[x];
                }
            }
    
            public long unite(long x, long y){
                var rx = getRoot(x);
                var ry = getRoot(y);
                if(rx == ry){
                    return rx;
                } else{
                    var sx = getSize(rx);
                    var sy = getSize(ry);
                    if(sx > sy){
                        size[rx] = sx+sy;
                        parents[ry] = rx;
                        return rx;
                    }else{
                        size[ry] = sx+sy;
                        parents[rx] = ry;
                        return ry;
                    }
                }
                
            }
    
            public long getSize(long x){
                return size[getRoot(x)];
            }
    
            
    
            public bool isSameTree(long x, long y){
                return getRoot(x) == getRoot(y);
            }
 
        }
    }


    
}


Measured memory_bytes: 24760