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
  
  var array = new Array[fuckingJob](n)
  val pq : PriorityQueue[fuckingJob] = PriorityQueue()(Ordering.by(_.money))
  var ans = 0L

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

  array.sortBy(_.days)

  for(i <- 0 until array.length)
    pq.enqueue(array(i))

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