'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(v => ~~v))
  const N = ~~input[0][0]
  const M = ~~input[0][1]
  const jobs = input.slice(1).sort((a, b) => {
    return a[0] - b[0] || b[1] - a[1] // Aの昇順、Bの降順
  })　
  let ans = 0

  let day = M - 1
  let marker = 0 // day が有効な、探索の開始位置

  for (let i = day; 0 <= i; i--) {
    // console.log(i)
    let _max = 0
    let _maxind = -1
    for (let j = marker; j < jobs.length; j++) {
      if (M - i >= jobs[j][0]) {
        // enable
        _max = Math.max(_max, jobs[j][1])
        _maxind = j
      } else {
        marker = j
        break
      }
    }
    if (_max >= 1) jobs[_maxind][1] = 0
    ans += _max
  }
  console.log(ans)
  return
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
