import std.conv, std.stdio;
import std.algorithm, std.range, std.string;
import std.container.rbtree;
import std.experimental.logger;

void main()
{
    auto buf = readln.chomp.split.to!(int[]);
    immutable n = buf[0], m = buf[1];
    Job[] jobs;
    foreach (i; 0..n)
    {
        buf = readln.chomp.split.to!(int[]);
        jobs ~= Job(buf[0], buf[1]);
    }
    jobs.sort();
    auto availableJobs = redBlackTree!(true, size_t);
    int totalReward;
    foreach (j; 1..m+1)
    {
        while (!jobs.empty && jobs.front.delay <= j)
        {
            availableJobs.insert(jobs.front.reward);
            jobs.popFront;
        }
        if (availableJobs.empty) continue;
        totalReward += availableJobs.back;
        availableJobs.removeBack;
    }
    totalReward.writeln;
}
struct Job
{
    size_t delay;
    size_t reward;
    int opCmp(in Job rhs)
    {
        if (this.delay  < rhs.delay ) return -1;
        if (this.delay  > rhs.delay ) return +1;
        if (this.reward > rhs.reward) return -1;
        if (this.reward < rhs.reward) return +1;
        return 0;
    }
}
