import numpy as np

N, C = map(int, input().split(" "))
x = [0]
v = [0]
for _ in range(N):
    t_x, t_v = map(int, input().split(" "))
    x.append(t_x)
    v.append(t_v)

x = np.array(x)
v = np.array(v)

dif_x = x - np.concatenate([[0], x[:-1]])
# dif_v = v - np.concatenate([[0], v[:-1]])
cal = v - dif_x

right = np.cumsum(cal)
right_max = right.max()
right_x = x[right.argmax()]

x_in = np.concatenate([[0], C - x[1:][::-1]])
dif_x_in = x_in - np.concatenate([[0], x_in[:-1]])
cal_in = np.concatenate([[0], v[1:][::-1]]) - dif_x_in

left = np.cumsum(np.abs(cal-C))

def calc_max(r, l, x, i):
  r_max = r[:i+1].max()
  l_max = l[:N-i].max()
  move = x[r[:i+1].argmax()]
  res = max(r_max, r_max + l_max - move)
  return res

res = [0]
for i in range(N):
  res.append(calc_max(right, cal_in, x, i))
  res.append(calc_max(cal_in, right, x_in, i))
  
print(max(res))
