/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3 4
4 3
4 1
2 2
---+/
/+---test
5 3
1 2
1 3
1 4
2 1
2 3
---+/
/+---test
1 1
2 1
---+/

struct Job {
  long day;
  long reward;
  bool used;
}

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  auto jobs = new Job[N];
  foreach (ref j; jobs) readf(" %d %d ", &j.day, &j.reward);
  jobs = jobs.sort!"a.reward > b.reward".array;

  long reward;
  foreach (day; 1..M+1) {
    const ji = jobs.countUntil!(x => !x.used && x.day <= day);
    if (ji < 0) continue;

    reward += jobs[ji].reward;
    jobs[ji].used = true;
  }
  reward.writeln;
}
