object Main{
  case class Job (days: Int, pay: Int)

  def main(args: Array[String]) : Unit = {
    val sc = new java.util.Scanner(System.in)
    val n,m = sc.nextInt
    val jobs = (1 to n)
      .map{_ => Job(sc.nextInt,sc.nextInt) }
      .groupBy { job => job.days }

    val candidate = collection.mutable.PriorityQueue[Int]()
    var result = 0
    (1 to m).foreach { x =>
      //candidate.addAll(jobs.getOrElse(x,List.empty))
      jobs.getOrElse(x,List.empty).foreach{job => candidate += job.pay }

      if(candidate.nonEmpty) {
        result += candidate.dequeue
      }
    }
    println(result)
  }
}

