import scala.collection.mutable.PriorityQueue

case class fuckingJob(days : Int , money : Int)

object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt() //job
  val m = sc.nextInt() //day
  var mwhile = m - 1
  val ab : PriorityQueue[fuckingJob] = PriorityQueue()(Ordering.by(_.money))
  var ans = 0

  for (i <- 0 until n) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    ab.enqueue(fuckingJob(a,b))
  }

  while(mwhile >= 0 && ab.nonEmpty){
    val wara  = ab.dequeue()
    if(wara.days <= mwhile+1){
      ans += wara.money
      mwhile = mwhile - 1
    }
  
  }
  
  println(ans)
}