n, c = map(int, input().split())
xvs = [tuple(map(int, input().split())) for _ in range(n)]

forward_cals = [(0, 0, 0)]
for x, v in xvs:
    cal, max_cal, pos = forward_cals[-1]
    new_cal = cal + v - (x - pos)
    new_max_cal = max(max_cal, new_cal)
    forward_cals.append((new_cal, new_max_cal, x))

backward_cals = [(0, 0, c)]
for x, v in reversed(xvs):
    cal, max_cal, pos = backward_cals[-1]
    new_cal = cal + v - (pos - x)
    new_max_cal = max(max_cal, new_cal)
    backward_cals.append((new_cal, new_max_cal, x))

ans = max((forward_cals[-1][1], backward_cals[-1][1]))

for (cal, max_cal, pos), (_, back_max, __) in zip(forward_cals, reversed(backward_cals)):
    ans = max(ans, cal - pos + back_max)

for (__, for_max, _), (cal, max_cal, pos) in zip(reversed(forward_cals), backward_cals):
    ans = max(ans, cal - (c-pos) + for_max)

print(ans)