def clockwisefirst(N, C, X, V):
    clockwise = [sum(V[:i+1]) - X[i] for i in range(N)]
    counterclockwise = [sum(V[i:]) - C + X[i] for i in range(N)]
    counterclockwise.append(0)

    clockwiselist = []
    clockwiselist.append(0)

    for i in range(N):
        backwardmax = max(counterclockwise[i+1:])
        clockwiselist.append(clockwise[i] + max(int(0), backwardmax - X[i]))

    return max(clockwiselist)



N, C = map(int, input().split())
X = []
V = []
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)

Y = [C - X[i] for i in range(N)]

maxcal = max(clockwisefirst(N, C, X, V), clockwisefirst(N, C, Y[::-1], V[::-1]))

print(maxcal)