import std.stdio, std.conv, std.array;
import std.algorithm;
import std.typecons;

alias Work = Tuple!(int, "id", int, "income", int, "delay", bool, "isUsed");

void main() {
  int N, DAYS;
  readf("%d %d\n", &N, &DAYS);

  Work[] works;
  works.length = N;

  foreach(i; 0..N) {
    int income, delay;
    readf("%d %d\n", &delay, &income);
    works[i] = Work(0, income, delay, false);
  }

  multiSort!("a.delay < b.delay", "a.income > b.income")(works);
  foreach(i; 0..N) {
    works[i].id = i;
  }

  uint income = 0;
  foreach(day; 1..DAYS+1) {
    auto works_candidates = filter!(a => !a.isUsed && a.delay <= day)(works).array;
    if (works_candidates.length == 0) continue;

    auto work = works_candidates.sort!("a.income > b.income")[0];
    // writeln(work);

    income += work.income;
    works[work.id].isUsed = true;
  }

  writeln(income);
}
