import sys
from itertools import accumulate


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, C = map(int, input().split())

    X_right = []
    X_left = []
    V_right = []

    for i in range(N):
        x, v = map(int, input().split())
        X_right.append(x)
        V_right.append(v)
        X_left.append(C - x)

    V_left = V_right[::-1]
    V_right_add = list(accumulate([0] + V_right))
    V_left_add = list(accumulate([0] + V_left))
    X_left = [0] + X_left[::-1]
    X_right = [0] + X_right

    Right = []
    answer_right = 0
    for i in range(N + 1):
        if answer_right < V_right_add[i] - X_right[i]:
            answer_right = V_right_add[i] - X_right[i]
        Right.append(answer_right)

    Right = Right[::-1]
    answer = Right[-1]
    for i in range(N + 1):
        if answer < V_left_add[i] - X_left[i] * 2 + Right[i]:
            answer = max(
                V_left_add[i] - X_left[i] * 2 + Right[i],
                V_left_add[i] - X_left[i] + Right[i] - X_right[N - i - 1],
                answer,
            )
    print(answer)


if __name__ == "__main__":
    main()
