# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
N, C = inpl()

S = [tuple(inpl()) for _ in range(N)]

R1 = [0]*N
R2 = [0]*N
L1 = [0]*N
L2 = [0]*N

cal = 0
nak = 0
ans1 = 0
ans2 = 0
for i, (x, v) in enumerate(S):
    cal += v
    ans1 = max(ans1, cal-x)
    ans2 = max(ans2, cal-2*x)
    R1[i] = ans1
    R2[i] = ans2


cal = 0
nak = 0
ans1 = 0
ans2 = 0
for i, (x, v) in enumerate(S[::-1]):
    x = C-x
    cal += v
    ans1 = max(ans1, cal-x)
    ans2 = max(ans2, cal-2*x)
    L1[-1-i] = ans1
    L2[-1-i] = ans2


ans = 0

for i in range(N-1):
    ans = max(ans, R2[i]+L1[i+1], R1[i]+L2[i+1])

ans = max(ans, R1[-1], L1[0])
print(ans)