import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias MaxHeap = BinaryHeap!(Array!int, "a < b");

int calc(int m, int[][] a) {
    a.sort!((a, b) => a[0] > b[0]);
    int p = cast(int)a.length - 1;

    int ans = 0;
    auto pq = new MaxHeap;
    for (int i = m-1; i >= 0; i--) {

        while (p >= 0 && a[p][0] + i <= m) {
            pq.insert(a[p][1]);
            p--;
        }

        if (pq.length > 0) {
            ans += pq.front;
            pq.popFront();
        }
    }

    return ans;
}

void main() {
    int n, m; scan(n, m);
    int[][] a;
    foreach (_; 0..n) a ~= readints;

    writeln(calc(m, a));
}
