N, C = map(int, input().split())
X = []
V = []
for i in range(N):
  x, v = map(int, input().split())
  X.append(x)
  V.append(v)

frontS = []
prevX = 0
v = 0
for i in range(N):
  v = v + V[i] - (X[i] - prevX)
  frontS.append(v)
  prevX= X[i]

# 後ろi個の中での累計MAX
backMaxS = []
prevX = C
v = 0
tmpMax = float('-inf')
for i in range(N-1, -1, -1):
  v = v + V[i] - (prevX - X[i])
  tmpMax = max(tmpMax, v)
  backMaxS.append(tmpMax)
  prevX = X[i]
backMaxS.reverse()
backMaxS.append(0)

ans = backMaxS[0]
for i in range(N):
  # X個まで食べて、退出 or 引き返す
  ans = max(
    ans,
    frontS[i],
    frontS[i] - X[i] + backMaxS[i+1]
  )

print(ans)