

object Main extends App {

  val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val ab = (0 until n).map { _ =>
    val Array(aa, bb) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    (bb, aa)
  }.sorted.reverse

  var ans = 0
  var day = 0
  var i = 0

  while (day < m && i < n) {
    while (i < n && ab(i)._2 + day > m) {
      i += 1
    }

    if (i < n) {
      ans += ab(i)._1
    }
    day += 1
    i += 1
  }

  println(ans)
}
