n, c = map(int, input().split())
xvs = [tuple(map(int, input().split())) for _ in range(n)]
mx1 = [0]
acc = 0
prv = 0
for x, v in xvs:
    acc += v - (x-prv)
    prv = x
    mx1.append(max(acc, mx1[-1]))
mx2 = [0]
acc = 0
prv = c
for x, v in xvs[::-1]:
    acc += v - (prv-x)*2
    prv = x
    mx2.append(max(acc, mx2[-1]))
ans1 = 0
for i in range(n+1):
    ans1 = max(ans1, mx1[n-i]+mx2[i])
mx1 = [0]
acc = 0
prv = 0
for x, v in xvs:
    acc += v - (x-prv)*2
    prv = x
    mx1.append(max(acc, mx1[-1]))
mx2 = [0]
acc = 0
prv = c
for x, v in xvs[::-1]:
    acc += v - (prv-x)
    prv = x
    mx2.append(max(acc, mx2[-1]))
ans2 = 0
for i in range(n+1):
    ans2 = max(ans2, mx1[n-i]+mx2[i])
print(max(ans1, ans2))