import java.lang.Math

fun main(args: Array<String>) {
    val (N, C) = readInputLine().split(" ").let { Pair(it[0].toInt(), it[1].toLong()) }

    val sushi = Array(N) {
        readInputLine().split(" ").let {
            Pair(it[0].toLong(), it[1].toLong())
        }
    }

    val clockwiseMax = LongArray(N)

    var currentCal = sushi[0].second
    clockwiseMax[0] = Math.max(0L, currentCal - sushi[0].first)

    for (i in 1 until N) {
        currentCal += sushi[i].second
        clockwiseMax[i] = Math.max(clockwiseMax[i - 1], currentCal - sushi[i].first)
    }

    val unclockwiseMax = LongArray(N)

    currentCal = sushi[N - 1].second
    unclockwiseMax[N - 1] = Math.max(0L, currentCal - (C - sushi[N - 1].first))

    for (i in N - 2 downTo 0) {
        currentCal += sushi[i].second
        unclockwiseMax[i] = Math.max(unclockwiseMax[i + 1], currentCal - (C - sushi[i].first))
    }

    var ans = 0L
    ans = Math.max(ans, clockwiseMax[N - 1])
    ans = Math.max(ans, unclockwiseMax[0])

    for (i in 0 until N - 2) {
        ans = Math.max(ans, clockwiseMax[i] + unclockwiseMax[i + 1] - sushi[i].first)
    }
    for (i in N - 1 downTo 1) {
        ans = Math.max(ans, unclockwiseMax[i] + clockwiseMax[i - 1] - (C - sushi[i].first))
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}
