fun main(args: Array<String>) {
    val (n, C) = readLine()!!.split(" ").map { it.toLong() }
    val N = n.toInt()
    val x = LongArray(N)
    val v = LongArray(N)
    (0 until N).forEach {
        val (a, b) = readLine()!!.split(" ").map { it.toLong() }
        x[it] = a
        v[it] = b
    }

    var max = 0L
    var cal = 0L
    var position = 0L
    // Start to right
    val r = LongArray(N)
    for (i in 0 until N) {
        val move = x[i] - position
        cal = cal + v[i] - move
        position = x[i]
        max = Math.max(max, cal)
        r[i] = max
    }

    val l = LongArray(N)
    max = 0L
    cal = 0L
    position = C
    for (i in N - 1 downTo  0) {
        val move = position - x[i]
        cal = cal + v[i] - move
        position = x[i]
        max = Math.max(max, cal)
        l[i] = max
    }

    var answer = Math.max(r[N - 1], l[0])
    // Start to left
    for (i in 0 until N - 1) {
        answer = Math.max(answer, r[i] + l[i + 1] - x[i])
    }
    for (i in N - 1 downTo  1) {
        answer = Math.max(answer, l[i] + r[i-1] - (C - x[i]))
    }

    println(answer)
}
