import java.util.*

fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val p = mutableListOf<Pair<Int, Int>>()
    (0 until N).forEach {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        p.add(Pair(a, b))
    }
    p.sortBy {
        it.first
    }

    var anser = 0L
    val queue = PriorityQueue<Int>()
    var pointer = 0
    (M -1 downTo  0).forEach {
       val a = M - it
       while (pointer < N && p[pointer].first <= a) {
           queue.offer(-1 * p[pointer].second)
           pointer++
       }
        if (!queue.isEmpty()) {
            val value = queue.poll()
            anser += -1 * value
        }
    }
    println(anser)
}