import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

alias Job = Tuple!(int, int);

void main() {
  auto input = readln.split.to!(int[]);
  auto N = input[0], M = input[1];
  auto jobs = new Job[N]; // [A_i, B_i]
  foreach(i; 0..N) {
    input = readln.split.to!(int[]);
    jobs[i] = tuple(input[0], input[1]);
  }
  auto aMinHeap = heapify!"a[0]>b[0]"(jobs);
  auto bMaxHeap = BinaryHeap!(Job[], "a[1]<b[1]")(new Job[N]);
  foreach(i; 0..N) {
    bMaxHeap.popFront();
  }

  ulong ans = 0;
  for(int d = M-1; d >= 0; d--) {
    while(!aMinHeap.empty && aMinHeap.front[0] <= M-d) {
      bMaxHeap.insert(aMinHeap.front); aMinHeap.popFront();
    }
    if(bMaxHeap.empty) continue;
    ans += bMaxHeap.front[1];
    bMaxHeap.popFront();
  }
  ans.writeln;
}
