import std.stdio, std.array, std.conv, std.container;

void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    int[][] job = new int[][](10000);
    foreach (i; 0 .. n) {
        tmp = readln.split.to!(int[]);
        int a = tmp[0] - 1, b = tmp[1];
        job[a] ~= b;
    }
    BinaryHeap!(int[]) h = BinaryHeap!(int[])(new int[n], 0);
    int ans;
    foreach (i; 0 .. m) {
        foreach (x; job[i]) {
            h.insert(x);
        }
        if (!h.empty) {
            ans += h.front;
            h.removeFront;
        }
    }
    ans.writeln;
}