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

void main()
{
    int n, m;
    readf("%s %s", &n, &m);
    readln;

    Tuple!(int, int)[] jobs;
    foreach (_; 0 .. n) {
        int a, b;
        readf("%s %s", &a, &b);
        readln;
        
        jobs ~= tuple(a, b);
    }
    
    auto rbt = make!(RedBlackTree!(int, "a < b", true));
    
    jobs.sort();
    
    debug { jobs.writeln; }
    
    long ans = 0;
    int j = 0;
    foreach (d; (m+1).iota.dropOne) {
        while (j < n && jobs[j][0] <= d) {
            rbt.insert(jobs[j][1]);
            ++j;
        }
       
        if (!rbt.empty()) {
            ans += rbt.back();
            rbt.removeBack();
        }
    }
    
    ans.writeln;
}