
import scala.collection.mutable.PriorityQueue


object Main {

  def main(args: Array[String]): Unit = {

    val Array(n,m) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val leftJobs = PriorityQueue.empty[(Int,Int)](Ordering.by[(Int,Int),Int](t => -t._1))
    val availables = PriorityQueue.empty[Int]

    (0 until n)
      .foreach(_ => {
        val Array(days,reward) = readLine().split(" ").map(_.toInt)
        leftJobs.enqueue(days -> reward)
      })

    val totalReward = (for { 
      leftDays <- 0 to m
    } yield {
      while(leftJobs.size > 0 && leftJobs.head._1 <= leftDays) {
        val v = leftJobs.dequeue()
        availables.enqueue(v._2)
      }

      if(availables.size == 0) {
        0
      } else {
        availables.dequeue()
      }
    }).sum

    println(totalReward)
  }

}