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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');

        var N = int.Parse(input[0]);
        var M = int.Parse(input[1]);
        var dict = new Dictionary<int, List<int>>();

        for(var i = 0; i < N; i++)
        {
            var array = Console.ReadLine().Split(' ');
            if (dict.ContainsKey(int.Parse(array[0])))
            {
                dict[int.Parse(array[0])].Add(int.Parse(array[1]));
            }
            else
            {
                dict.Add(int.Parse(array[0]), new List<int>() { int.Parse(array[1]) });
                
            }

        }

        var priorityQueue = new PriorityQueue<int>(1);
        var ans = 0;
        var count = 0;
        for (var i = 0; i < M + 1; i++)
        {
            if (dict.ContainsKey(i))
            {
                foreach (var n in dict[i])
                {
                    priorityQueue.Enqueue(n);
                    count++;
                }
            }
            if (count > 0)
            {
                ans += priorityQueue.Dequeue();
                count--;
            }
        }

        Console.WriteLine(ans);

        Console.ReadLine();
    }


}

public class PriorityQueue<T> where T : IComparable
{

    public IComparer<T> Comparer { get; set; }

    public List<T> Heap { get; set; }

    //0=デフォルトで昇順、1で降順
    public int Type { get; set; }

    public PriorityQueue()
    {
        //this.Heap = new T[maxSize];
        this.Heap = new List<T>();
        this.Type = 0;
    }

    public PriorityQueue(int type)
    {
        this.Heap = new List<T>();
        this.Type = type;
    }

    public PriorityQueue(PriorityQueueTypeOrderType type)
    {
        this.Heap = new List<T>();
        this.Type = (int)type;
    }

    public int Compare(T x, T y)
    {
        return this.Type == 0 ? x.CompareTo(y) : y.CompareTo(x);
    }

    public void Enqueue(T n)
    {
        this.Heap.Add(n);

        var child = this.Heap.Count - 1;

        while (child > 0)
        {
            var parent = (child - 1) / 2;

            if (this.Compare(n, this.Heap[parent]) >= 0)
            {
                break;
            }
            var temp = this.Heap[child];
            this.Heap[child] = this.Heap[parent];
            this.Heap[parent] = temp;
            child = parent;

        }
    }

    public T Dequeue()
    {
        var last = this.Heap.Count - 1;
        var result = this.Heap[0];
        this.Heap[0] = this.Heap[last];
        this.Heap.RemoveAt(last);
        last--;
        var parent = 0;
        while (true)
        {
            var child = parent * 2 + 1;
            if (child > last)
            {
                break;
            }
            var rightChild = child + 1;
            if (rightChild <= last && Compare(this.Heap[rightChild], this.Heap[child]) < 0)
            {
                child = rightChild;
            }
            if (Compare(this.Heap[parent], this.Heap[child]) <= 0)
            {
                break;
            }

            var temp = this.Heap[child];
            this.Heap[child] = this.Heap[parent];
            this.Heap[parent] = temp;

            parent = child;
        }
        return result;
    }
}

public enum PriorityQueueTypeOrderType
{
    Ascending = 0,
    Descending = 1,
}

Measured memory_bytes: 33404