import java.util.PriorityQueue

fun main(args: Array<String>)
{
    val (n, m) = readNInts()
    val ptj = Array<MutableList<Int>>(m, { mutableListOf<Int>() })
    for (i in 1..n)
    {
        val (a, b) = readNInts()
        if (a > m) continue
        ptj[m - a].add(-b)
    }

    var ans = 0L
    val q = PriorityQueue<Int>()
    for (i in m-1 downTo 0)
    {
        for (b in ptj[i])
        {
            q.offer(b)
        }

        if (!q.isEmpty())
        {
            ans += -q.poll().toLong()
        }
    }

    println(ans)
}

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
fun readNInts() = readLine()!!.split(" ").map(String::toInt)
