fun main(args: Array<String>) {
    val (Nl, C) = listOfLong()
    val N = Nl.toInt()
    val x = LongArray(N + 1)
    val v = IntArray(N + 1)
    val sL = LongArray(N + 1)
    val sR = LongArray(N + 1)
    val sLM = LongArray(N + 1)
    val sRM = LongArray(N + 1)
    val sLTM = LongArray(N + 1)
    val sRTM = LongArray(N + 1)
    for (n in 1..N) {
        val (X, V) = listOfLong()
        x[n] = X; v[n] = V.toInt()
        sL[n] = sL[n - 1] + v[n]
    }
    for (n in 1..N) {
        sR[n] = sR[n - 1] + v[N - n + 1]
    }
    for (n in 1..N) {
        sLM[n] = Math.max(sLM[n - 1], sL[n] - x[n])
        sRM[n] = Math.max(sRM[n - 1], sR[n] - (C - x[N - n + 1]))
    }
    for (n in 1..N) {
        sLTM[n] = Math.max(sLTM[n - 1], sL[n] - 2 * x[n] + sRM[N - n])
        sRTM[n] = Math.max(sRTM[n - 1], sR[n] - 2 * (C - x[N - n + 1]) + sLM[N - n]
        )
    }
    val ans = Math.max(
        Math.max(sLM[N], sRM[N]),
        Math.max(sLTM[N], sRTM[N])
    )
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong(d: Int = 0) = listOfString().map { it.toLong() + d }

