n,c1 = map(int, input().split())
g = []
c = [0]
d = [0]
a = 0
ans=[]
for i in range(n):
  x,v = map(int, input().split())
  g.append([x,v])
  a+=v
  c.append(a-x)
  d.append(a-2*x)
b = 0
e = [0]
f = [0]
for i,j in reversed(g):
  b+=j
  e.append(b-(c1-i))
  f.append(b-2*(c1-i))
for i in range(1,n+2):
  ans.append(max(c[:i])+f[-i])
  ans.append(max(d[:i])+e[-i])
print(max(ans))