from numpy import *
n,c = (int(i) for i in input().split())  
xs = []
ys = []

for j in range(n):
  x,y = (int(i) for i in input().split())  
  xs.append(x)
  ys.append(y)
left = [[0,0]]
right = [[0,0]]
for j in range(n):
  left.append([left[-1][0]+ys[j]-(xs[j]-left[-1][1]),xs[j]])

for j in range(n)[::-1]:
  right.append([right[-1][0]+ys[j]-(right[-1][1]+c-xs[j]),xs[j]-c])
anss = []
anss.append(max(l[0] for l in right))
anss.append(max(l[0] for l in left))

for i in range(1,n):
  anss.append(left[i][0]-xs[i-1]+max(l[0] for l in right[1:-i]))
for i in range(1,n):
  anss.append(right[i][0]+right[i][1]+max(l[0] for l in left[1:-i]))
print(max(anss))