class Mansion(val position:Long, population:Long) {
    private var mPopulation: Long = population
    val population: Long
        get() = mPopulation

    fun mergeFrom(other: Mansion): Unit {
        mPopulation += other.mPopulation
    }
}

fun main(args:Array<String>):Unit{
    val maxPopulation = 1L shl 60//最大人口を超える値
    val (n, s) = readLine()!!.split(' ').map(String::toInt)
    val mansions = mutableListOf<Mansion>().apply {
        for (i in 0 until n) {
            val (x, p) = readLine()!!.split(' ').map(String::toLong)
            add(Mansion(x, p))
        }
        add(Mansion(s.toLong(), maxPopulation))
        sortBy(Mansion::position)
    }
    var time = 0L
    while (mansions.size != 1){
        if (mansions.size != 1 && mansions.first().population >= mansions.last().population) {
            time += mansions.last().position - mansions.first().position
            while (mansions.size != 1 && mansions.first().population >= mansions.last().population) {
                mansions.first().mergeFrom(mansions.removeAt(mansions.size - 1))
            }
        }
        if (mansions.size != 1 && mansions.last().population > mansions.first().population) {
            time += mansions.last().position - mansions.first().position
            while (mansions.size != 1 && mansions.last().population > mansions.first().population) {
                mansions.last().mergeFrom(mansions.removeAt(0))
            }
        }
    }
    println(time)
}