fun main(args: Array<String>) {
    val (Nl, C) = listOfLong()
    val N = Nl.toInt()
    val x = LongArray(N)
    val v = LongArray(N)
    repeat(N) { n ->
        val (X, V) = listOfLong()
        x[n] = X; v[n] = V
    }
    val dl = LongArray(N + 1)
    val dr = LongArray(N + 1)
    repeat(N) { n -> dl[n + 1] = dl[n] + v[n] }
    repeat(N) { n -> dr[n + 1] = dr[n] + v[N - 1 - n] }
    val dp1 = LongArray(N + 1)
    val dp2 = LongArray(N + 1)
    repeat(N) { n ->
        dp1[n + 1] = Math.max(dp1[n], dl[n] + v[n] - x[n])
        dp2[n + 1] = Math.max(dp2[n], dr[n] + v[N - 1 - n] - (C - x[N - n - 1]))
    }
    var ans = 0L
    repeat(N + 1) { n ->
        ans = Math.max(ans, dp1[n] + dp2[N - n] - (if (n == 0) 0 else x[n - 1]))
        ans = Math.max(ans, dp1[n] + dp2[N - n] - (if (n == N) 0 else (C - x[n])))
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong(d: Int = 0) = listOfString().map { it.toLong() + d }
