N,C = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

c1 = []
c2 = []
cumv = 0
for x,v in src:
    cumv += v
    c1.append(cumv - x)
    c2.append(cumv - 2*x)

r1 = []
r2 = []
cumv = 0
for x,v in reversed(src):
    cumv += v
    x = C-x
    r1.append(cumv - x)
    r2.append(cumv - 2*x)

ans = max(c1+r1+[0])
for i,c in enumerate(c2):
    for r in r1[:N-i-1]:
        ans = max(ans, c+r)
for i,r in enumerate(r2):
    for c in c1[:N-i-1]:
        ans = max(ans, c+r)

print(ans)
