import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto nm = readNums!int;
  auto n = nm[0], m = nm[1];

  auto ab = new int[][](n, 2);
  foreach(ref e; ab){
    e = readNums!int;
  }

  multiSort!("a[1] > b[1]", "a[0] > b[0]")(ab);
  ulong ret;

  auto p = new bool[](m);
  foreach(ref e; ab){
    foreach(ref f; p[e[0]-1 .. $]){
      if(!f){
        f = true;
        ret += e[1];
        break;
      }
    }
  }

  writeln(ret);
}
