function Main(input) {
  var len = parseInt(input.split("\n")[0].split(" ")[0]);
  var nissu = parseInt(input.split("\n")[0].split(" ")[1]);
  var list = [];
  var output = 0;
  for(var i = 1; i <= len; i++){
    var tmp = make(input.split("\n")[i]);
    if(tmp["a"] > nissu){
       continue;
    }
    list.push(tmp);
  }
  list.sort(function(a, b){
    if(a["a"] == b["a"]){
       return b["b"] - a["b"];
    }else{
       return a["a"] - b["a"];
    }
  });
  
 // console.log(list);
  
  for(var i = 0; i < nissu; i++){
    var max = 0;
    var lastSelect = -1;
    var breakFlag = false;
    for(var j = 0; j < list.length; j++){
      var tmp = list[j];
      if(tmp["a"] > i + 1){
        //console.log(JSON.stringify(tmp) + ",i:" + i + ",j:" + j + "NG");
        if(lastSelect == -1){breakFlag = true; /*console.log("lastなし");*/}
        break;
      }else{
        //console.log(JSON.stringify(tmp) + ",i:" + i + ",j:" + j + "OK");
         if(max < tmp["b"]){
           // console.log(JSON.stringify(tmp) + ",i:" + i + ",j:" + j + "OKOK");
            max = tmp["b"];
           lastSelect = j;
         }
      }
    }
    if(breakFlag){
       continue;
    }
    //console.log(max);
    list.splice(lastSelect, 1);
    output += max;
  }
  console.log(output);
}

function make(str){
  var tmp = {};
  tmp["a"] = parseInt(str.split(" ")[0]);
  tmp["b"] = parseInt(str.split(" ")[1]);
  return tmp;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
