import scala.io.StdIn.readLine
import scala.io.Source

object Main extends App {
  val input = Source.stdin.getLines().toList.map { str =>
    val List(a, b) = str.split(' ').toList.map(_.toInt)
    (a, b)
  }
  val header::works = input
  val (n, m) = header
  val sortedWorks = works.sorted(new Ordering[(Int, Int)]() {
    override def compare(x: (Int, Int), y: (Int, Int)): Int = {
      if (x == y) {
        0
      } else {
        val cmp = x._2.compareTo(y._2)
        if (cmp == 0) {
          x._1.compareTo(y._1)
        } else {
          cmp
        }
      }
    }
  }).reverse

  val result = sortedWorks.foldLeft((m, 0)) { case ((remainDays, sumOfReward), (days, reward)) =>
    if (days <= remainDays) {
      // 仕事するので1日分残り少なくなる
      (remainDays - 1, sumOfReward + reward)
    } else {
      (remainDays, sumOfReward)
  	}
  }
  println(result._2)
}