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

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val jobs = Array(n) {
        readLine()!!.split(" ").map { it.toInt() }.let { Job(it[0], it[1]) }
    }
    jobs.sortWith(compareByDescending<Job> { it.b }.thenByDescending { it.a })
    val set: TreeSet<Int> = TreeSet((0 until n).toList())
    var ans = 0
    jobs.forEachIndexed { index, job ->
        val insertP = m - job.a
        val ret = set.floor(insertP)
        if (ret != null) {
            set.remove(ret)
            ans += job.b
        }
    }
    println(ans)
}

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