import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = N.iota.map!(_ => readln.split.map!(to!int).array).array;
    A.sort!"a[0] < b[0]";

    int p = 0;
    long ans = 0;
    auto pq = new BinaryHeap!(Array!int, "a < b");

    foreach_reverse (i; 0..M+1) {
        while (p < N && i + A[p][0] <= M) {
            pq.insert(A[p][1]);
            ++p;
        }
        if (!pq.empty) {
            ans += pq.front;
            pq.removeFront;
        }
    }

    ans.writeln;
}
