import java.util.PriorityQueue

fun main(args: Array<String>) {
    var (N, M) = readInputLine().split(" ").map{it.toInt()}
    
    val works = PriorityQueue<Pair<Int, Int>>(N, {x, y -> if (x.first < y.first) -1 else if (x.first == y.first) {if (x.second > y.second) -1 else if (x.second == y.second) 0 else 1} else 1})
    
    for (i in 1..N) {
        val (A, B) = readInputLine().split(" ").map{it.toInt()}
        works.add(Pair(A, B))
    }

    val queue = PriorityQueue<Pair<Int, Int>>(N, {x, y -> if (x.second > y.second) -1 else if (x.second == y.second) 0 else 1})
    
    var ans = 0
    
    for (i in 1..M) {
        val work = works.peek() ?: Pair(Int.MAX_VALUE, 0)
        if (work.first > i) {
            ans += queue.poll()?.second ?: 0
        } else {
            val queueWork = queue.peek() ?: Pair(0, 0)
            if (work.second > queueWork.second) {
                ans += work.second
                works.poll()
            } else {
                ans += queue.poll()?.second ?: 0
            }
        }
        
        while (works.size != 0) {
            val work = works.poll()
            if (work.first > i) {
                works.add(work)
                break
            } else {
                queue.add(work)
            }
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}
