import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val ps = Array(N) {
        val (A, B) = readLine()!!.split(" ").map{it.toLong()}
        Pair(A, B)
    }

    ps.sortWith(Comparator{ a, b -> if (a.first != b.first) (a.first - b.first).toInt() else (b.second - a.second).toInt()})

    val Q = PriorityQueue<Long>(N, Comparator{ a, b -> b.compareTo(a)})
    var p = 0
    var res = 0L

    for (t in M downTo 0) {
        while (p < ps.size && M - ps[p].first >= t) {
            Q.add(ps[p].second)
            p++
        }
        if (Q.isNotEmpty()) {
            res += Q.poll()
        }
    }

    println(res)
}
