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

c1 = []
c2 = []
c1x = []
cumv = 0
c1max = -float('inf')
for x,v in src:
    cumv += v
    c1.append(cumv - x)
    c2.append(cumv - 2*x)
    c1max = max(c1max, c1[-1])
    c1x.append(c1max)

r1 = []
r2 = []
r1x = []
cumv = 0
r1max = -float('inf')
for x,v in reversed(src):
    cumv += v
    x = C-x
    r1.append(cumv - x)
    r2.append(cumv - 2*x)
    r1max = max(r1max, r1[-1])
    r1x.append(r1max)

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

print(ans)
