using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        int M = NextInt();
        Pair[] AB = Enumerable.Range(0, N).Select(v => new Pair(NextInt(), NextInt())).ToArray();
        var ab = AB.OrderByDescending(x => x.x).ThenByDescending(v => v.y).ToList();
        PriorityQueue<long, long> PQ = new PriorityQueue<long, long>();
        for (int i = 0; i < N; i++)
        {
            //0 - (M-Ai)日まで自由な日にできる
            if (PQ.Count() <= M - ab[i].x)
            {
                //ウケられる
                PQ.Add(ab[i].y, ab[i].y);
            }
            else
            {
                //小さい要素を追い出せる
                if (PQ.Count() != 0 && PQ.Peek() < ab[i].y)
                {
                    PQ.Poll();
                    PQ.Add(ab[i].y, ab[i].y);
                }
            }
        }
        long ans = 0;
        while (PQ.Count() != 0) ans += PQ.Take();
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 0) return 1;
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
}
public class PriorityQueue<Tkey, Tvalue> where Tkey : IComparable
{
    private List<Tkey> keys = new List<Tkey>();
    private List<Tvalue> values = new List<Tvalue>();
    private int size = 0;
    private static bool Descending;
    private static int Compare(Tkey a, Tkey b) { return (Descending ? a.CompareTo(b) : b.CompareTo(a)); }

    public PriorityQueue(bool b = true) { Clear(); Descending = b; }
    public int Count() { return size; }
    public void Clear() { keys = new List<Tkey>(); values = new List<Tvalue>(); size = 0; }
    public void Add(Tkey e, Tvalue v)
    {
        keys.Add(e);
        values.Add(v);
        int x = size;
        size += 1;
        while (x != 0)
        {
            int par = (x % 2 == 0 ? x - 2 : x - 1) / 2;
            if (Compare(keys[par], e) <= 0) break;
            Tkey a = keys[x]; keys[x] = keys[par]; keys[par] = a;
            Tvalue b = values[x]; values[x] = values[par]; values[par] = b;
            x = par;
        }
    }
    public void Poll()
    {
        Tkey k = keys[size - 1];
        Tvalue v = values[size - 1];
        int x = 0;
        size--;
        if (size == 0) { Clear(); return; }
        keys.RemoveAt(size);
        values.RemoveAt(size);
        while (true)
        {
            int l = x * 2 + 1;
            int r = x * 2 + 2;
            if (size - 1 < l) break;
            int y = 0;
            if (size - 1 == l) { y = l; }
            else if (Compare(keys[l], keys[r]) == 1) { y = r; }
            else { y = l; }
            if (Compare(keys[y], k) > 0) break;
            keys[x] = keys[y];
            values[x] = values[y];
            x = y;
        }
        keys[x] = k;
        values[x] = v;
    }
    public Tvalue Take() { Tvalue ret = values[0]; Poll(); return ret; }
    public Tvalue Peek() { return values[0]; }
    public void Debug()
    {
        Console.Write("key   : ");
        foreach (var k in keys) Console.Write(k + " ");
        Console.WriteLine();
        Console.Write("value : ");
        foreach (var k in values) Console.Write(k + " ");
        Console.WriteLine();
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 27792