'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const NM = inp.shift().split(' ').map(n => Number(n))
  inp = inp.map(r => r.split(' ').map(n => Number(n)))
    .sort((a, b) => {
      let diff = b[1] - a[1]
      return diff || a[0] - b[0]
    })
  let ans = 0;

  for (let i = 1; i <= NM[1]; i++) {
    for (let j = 0; j < inp.length; j++) {
      if (inp[j][0] <= i) {
        ans += inp[j][1]
        inp.splice(j, 1)
        break;
      }
    }
  }

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
