import numpy as np
import sys
input2 = sys.stdin.read

n, c = map(int, input().split())
AV = np.array(list(map(int, input2().rsplit())), dtype=np.int64)
A, V = AV[::2], AV[1::2]
B = (c - A)[::-1]
XA = np.cumsum(V) - A
XB = np.cumsum(V[::-1]) - B
RSA, RSB = XA - A, XB - B

XRA, XRB = 0, 0
for i in range(n):
    if RSA[i] > 0:
        XRA = max(XRA, RSA[i] + XB[:n - 1 - i].max())
    else:
        break

for i in range(n):
    if RSB[i] > 0:
        XRB = max(XRB, RSB[i] + XA[:n - 1 - i].max())
    else:
        break

print(max(0, max(XA), max(XB), XRA, XRB))
