'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 || b[0] - a[0]
    })
  let ans = 0;

  let i = 1
  while (i <= NM[1] && inp.length) {
    if (inp[0][0] + i - 1 <= NM[1]) {
      ans += inp[0][1]
      i++
    }
    inp.shift()
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
