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

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

    System.err.println(jobs)

    val candidate = collection.mutable.PriorityQueue[Job]()(Ordering.by{job => job.pay})
    var result = 0
    (1 to m).foreach { x =>
      System.err.println(x)

      jobs.getOrElse(x,List.empty).foreach{
        job => 
          candidate += job
      }

      var select:Job = null
      if(! candidate.isEmpty) {
        select = candidate.dequeue
        System.err.println(select)
        result += select.pay
      }
    }
    println(result)
  }
}

