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

# A: Anti-clockwise, B: Clockwise, V: Values
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    # Cumulative Values returning to Start

MA, MB = max(XA[:-1], default=0), max(XB[:-1], default=0)
MXA, MXB = XA.max(), XB.max()
mai, mbi = 0, 0

for i, x in enumerate(XA):
    if x == MA:
        mai = i

for i, x in enumerate(XB):
    if x == MB:
        mbi = i

MRA = max(0, max(RSA[:n - 1 - mbi], default=0))
MRB = max(0, max(RSB[:n - 1 - mai], default=0))

print(max(MA + MRB, MB + MRA, MXA, MXB))
