import java.util.*
import kotlin.comparisons.compareByDescending

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val p = Array(n) {
        readLine()!!.split(" ").map { it.toInt() }.let { Jobs(it[0], it[1]) }
    }
    p.sortBy { it.a }

    var ans = 0L
    var pointer = 0
    val queue = PriorityQueue<Int>(1, compareByDescending { it })
    repeat(m) {
        while (pointer < n && p[pointer].a <= it + 1) {
            queue.add(p[pointer].b)
            pointer++
        }
        ans += queue.poll() ?: 0
    }
    println(ans)
}

class Jobs(val a: Int, val b: Int)