using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using System.IO;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            var M = consoleReader.Int;
            var works = consoleReader.Repeat(N).Select(cr => new PartTimeWork { days = cr.Int, pay = cr.Int })
                .Where(w => w.days <= M)
                .OrderBy(w => w.days)
                .ToArray();

            var remaining = new PriorityQueue<int, object>(Comparer<int>.Create((p1, p2) => p2 - p1));
            long pay = 0;
            var i = 0;

            for (int d = 1; d <= M; d++)
            {
                while (i < works.Length && works[i].days <= d)
                {
                    var p = works[i++].pay;
                    remaining.Add(p, null);
                }

                if (remaining.Count > 0)
                {
                    var first = remaining.Dequeue();
                    pay += first.Key;
                }
            }

            return pay;
        }
        struct PartTimeWork
        {
            public override string ToString() => $"days:{days}, pay:{pay}";
            public int days;
            public int pay;
        }
        class PriorityQueue<TKey, TValue>
        {
            SortedDictionary<TKey, Queue<TValue>> dic;

            public int Count { get; private set; } = 0;

            public void Add(TKey key, TValue value)
            {
                if (!dic.ContainsKey(key)) dic[key] = new Queue<TValue>();

                dic[key].Enqueue(value);
                Count++;
            }

            public KeyValuePair<TKey, TValue> Dequeue()
            {
                var queue = dic.First();
                if (queue.Value.Count <= 1) dic.Remove(queue.Key);
                Count--;
                return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue());
            }
            public PriorityQueue() { dic = new SortedDictionary<TKey, Queue<TValue>>(); }
            public PriorityQueue(IComparer<TKey> comparer) { dic = new SortedDictionary<TKey, Queue<TValue>>(comparer); }
        }


        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private Queue<string> queue = new Queue<string>();
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (queue.Count > 0) return queue.Dequeue();
                var line = textReader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 1; i < line.Length; i++) queue.Enqueue(line[i]);
                return line[0];
            }
        }
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 26304