#!python3

# input
N, C = list(map(int, input().split()))
X, V = [0] * (N + 1), [None] * N
for i in range(N):
    X[i + 1], V[i] = list(map(int, input().split()))


def main():
    Vsum = [0] * (N + 1)
    for i in range(N):
        Vsum[i + 1] = Vsum[i] + V[i]
    
    A, B = [0] * (N + 1), [0] * (N + 1)
    for i in range(1, N + 1):
        A[i] = max(A[i - 1], Vsum[i] - X[i])
        B[i] = max(B[i - 1], Vsum[-1] - Vsum[-1 - i] - (C - X[-i]))
    
    ans = 0
    for i in range(1, N):
        ans = max(ans, A[i] + B[N - i] - X[i])
    for i in range(1, N):
        ans = max(ans, B[i] + A[N - i] - (C - X[-i]))
    ans = max(ans, A[N])
    ans = max(ans, B[N])

    print(ans)


if __name__ == "__main__":
    main()
