using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)998244353;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var AB = new List<Tuple<long, long>>();
            for (var i = 0; i < N; ++i)
            {
                var ab = Sarray();
                AB.Add(Tuple.Create(ab[0], ab[1]));
            }
            AB.Sort((l, r) => (int)(r.Item2 - l.Item2));
            var st = new SegTree((int)M);
            var ans = 0L;
            foreach (var ab in AB)
            {
                var fd = st.GetFreeday((int)ab.Item1);
                if (fd == -1) continue;
                st.Set(fd, false);
                ans += ab.Item2;
            }
            WriteLine(ans);
            //Out.Flush();
        }
        public class SegTree
        {
            int N;
            int ON = int.MaxValue;
            // left | right
            bool[] val;
            public SegTree(int n)
            {
                N = 2;
                while (N < n)
                    N <<= 1;
                val = Enumerable.Repeat(true, 2 * N - 1).ToArray();
                for (var i = n + 1; i <= N; ++i)
                    Set(i, false);
                ON = n;
            }

            public void Set(int n, bool v)
            {
                if (ON < n) return;
                var i = N - 1 + n;
                if (GetValue(i) != v)
                {
                    SetValue(i, v);
                    _chg(i);
                }
            }
            // nが変更された
            void _chg(int n)
            {
                var p = Parent(n);
                if (p < 1) return;
                var v = GetValue(Left(p)) | GetValue(Right(p));
                if (GetValue(p) != v)
                {
                    SetValue(p, v);
                    _chg(p);
                }
            }
            public int GetFreeday(int n)
            {
                if (ON < n) return -1;
                var i = N - 1 + n;
                if (GetValue(i))
                    return n;
                // 右側にあるtrueを探す
                var pre = i;
                var next = Parent(pre);
                while (0 < next && !(Left(next) == pre && GetValue(Right(next))))
                {
                    pre = next;
                    next = Parent(pre);
                }
                if (next < 1) return -1;

                next = Right(next);
                while (next < N)
                {
                    next = Left(next);
                    if (!GetValue(next)) next = Right(Parent(next));
                }
                return next - (N - 1);
            }
            // 1開始
            bool GetValue(int n) => val[n - 1];
            void SetValue(int n, bool v) => val[n - 1] = v;
            int Parent(int n) => n / 2;
            int Left(int n) => n * 2;
            int Right(int n) => n * 2 + 1;
        }
    }
}

Measured memory_bytes: 24892