import scala.io.StdIn._
import scala.collection.mutable

object Main extends App {
  case class Job(day: Int, amount: Int)

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

  val jobs: Seq[Job] = for {
    i <- 1 to n
  } yield {
    val line = readLine.split(" ").map(_.toInt)
    Job(line(0), line(1))
  }

  val jobGroups = jobs.groupBy(_.day)
  val queue = collection.mutable.PriorityQueue[Int]()
  var ans = 0
  (1 to m).foreach { x =>
    jobGroups.getOrElse(x, Nil).foreach { job => queue += job.amount }

    if(queue.nonEmpty) {
      ans += queue.dequeue
    }
  }
  println(ans)
}
