import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val A = new Array[Int](N+1)
  val B = new Array[Int](N+1)
  val ab = new PriorityQueue[(Int, Int)]()
  for (i <- 1 to N) {
    val a, b = in.next().toInt
    A(i) = a; B(i) = b
    ab.enqueue((-a, b))
  }

  //
  var ans = 0L
  val pq = new PriorityQueue[Int]()
  for (d <- 1 to M) {
    breakable {
      while (!ab.isEmpty) {
        if (-ab.head._1 <= d) {
          val (_, b) = ab.dequeue()
          pq.enqueue(b)
        }
        else {
          break
        }
      }
    }

    if (!pq.isEmpty) {
      ans += pq.dequeue()
    }
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
