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

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val ab = Array(n) { AB(scanner.nextInt(), scanner.nextLong()) }

    val comp = compareByDescending<Pair<Long, Long>> { it.second }
        .thenByDescending { it.first }

    val dayasc = ab.sortedWith(compareBy { it.a })
    val pq = PriorityQueue<AB>()

    var ret = 0L
    var di = 0
    (0..m).forEach { day ->
        while (di < dayasc.size && dayasc[di].a == day) {
            pq.add(dayasc[di])
            di++
        }

        if (pq.isEmpty()) return@forEach

        val w = pq.poll()
        ret += w.b

    }

    println(ret)
}

data class AB(val a: Int, val b: Long) : Comparable<AB> {
    override fun compareTo(other: AB): Int {
        return compareValues(other.b, b)
    }
}