'use strict'

function Main(input) {
  const M = Number(input.split("\n")[0].split(" ")[1])
  let list = input.split("\n").slice(1)
    .map(x => x.split(" ")
    .map(x => Number(x)))
    .filter(x => x[0] <= M)
    .sort((a, b) => {
      if(a[1] === b[1]) {
        return b[0] - a[0]
      } else {
        return b[1] - a[1]
      }
    })
  if(list.length === 0) {
    console.log(0)
    return
  }

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

  console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())
