
N, C = input().split(' ')
N = int(N)
C = int(C)
xs, vs = [], []
for n in range(N):
    x, v = input().split(' ')
    xs.append(int(x))
    vs.append(int(v))

dp_r = []
for i in range(N):
    dp_r.append(sum(vs[:i+1]) - xs[i])
dp_l = []
rev_vs = list(reversed(vs))
rev_xs = list(reversed(xs))
for i in range(N):
    dp_l.append(sum(rev_vs[:i+1]) - (C-rev_xs[i]))

max_right = max(dp_r)
max_left = max(dp_l)

max_bothes = [0]
for i in range(1, N-1):
    mr = max(dp_r[:i])
    max_bothes.append(mr - xs[dp_r.index(mr)] + max(dp_l[:N-dp_r.index(mr)-1]))
max_both = max(max_bothes)

print(max([0, max_right, max_left, max_both]))
