'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] || a[1] - b[1] // Aの昇順、Bの降順
  })
  // let _ = input.slice(1)
  // const jobs = []
  // for (let i = 0; i < N; i++) {
  //   if (!jobs[_[i][0]]) jobs[_[i][0]] = []
  //   jobs[_[i][0]].push(_[i][1])
  // }
  // console.log(N, M, jobs) // 1000000000 = 1e9

  let ans = 0

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

  for (let i = day; 0 <= i; i--) {
    // console.log(i)
    let _max = 0
    let _maxind = -1
    for (let j = 0; j < marker; j++) {
      if (M - i >= jobs[j][0]) {
        // console.log(M - i, jobs[j][0], jobs[j][1])
        // enable
        if (_max < jobs[j][1]) {
          _max = jobs[j][1]
          _maxind = j
        }
      } else {
        marker = j + 2 <= N ? j + 2 : N // j- 2 > 0 ? j - 2 : 0
        break
      }
    }
    if (_max >= 1) jobs[_maxind][1] = 0 // jobs.splice(_maxind, 1)
    // console.log(_max)
    ans += _max
  }
  // console.log('----')
  console.log(ans)
  // console.log('----')

  return
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
