from itertools import accumulate
from operator import sub

N, C = map(int, input().split())
xs = []
vs = []
for i in range(N):
    x, v = map(int, input().split())
    xs += [x]
    vs += [v]
xs += [C]
vs += [0]

fAs = accumulate(vs)
fAs = [(fA, -xA) for fA, xA in zip(map(sub, fAs, xs), xs)]
gAs = list(accumulate([(0, 0)] + fAs[:-1], max))

ans = 0
eneIn = 0
for B in reversed(range(N + 1)):
    eneIn += vs[B]
    eneOut = C - xs[B]
    ans1 = eneIn - eneOut + max(0, -eneOut + gAs[B][0])
    ans2 = gAs[B][0] + max(0, gAs[B][1] + eneIn - eneOut)
    ans = max(ans, ans1, ans2)

print(ans)
