'use strict';(function(input){
  
  input=input.trim().split(/\n+/);
  input=input.map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0],
        M=input[0][1];
  input.shift();
  input.sort((I,J)=>(J[1]-I[1])?(J[1]-I[1]):(J[0]-I[0]));
  
  var ans=0;
  var days=new Array(M).fill(0);
  
  for(let i=0;i<N;i++){
    let A=input[i][0];
    while(days[M-A])
      A++;
    if(A>=M+1){
      continue;
    }else{
      days[M-A]+=1;
      ans+=input[i][1];
    }
  }
  
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));
