import scala.io.StdIn._
import scala.collection.mutable.{ArrayBuffer, PriorityQueue}
object Main extends App {
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val arbeits = Array.fill(m + 1)(new ArrayBuffer[Int]())
  for (i <- 1 to n) {
    val Array(a, b) = readLine.split(" ").map(_.toInt)
    arbeits(a) += b
  }

  def exec(day: Int, possible: PriorityQueue[Int], income: Int): Int = {
    println(s"$day, $possible, $income")
    if (day > m) income
    else {
      val newPossible = possible ++ arbeits(day)
      if (newPossible.isEmpty) {
        exec(day + 1, newPossible, income)
      } else {
        val a = newPossible.dequeue()
        exec(day + 1, newPossible, income + a)
      }
    }
  }

  println(exec(1, PriorityQueue[Int](), 0))
}