import numpy as np

n, c = map(int, input().split())
x_cw = np.empty(n)
v = np.empty(n)

for i in range(n):
    x_cw[i], v[i] = map(int, input().split())
    
x_ccw = c - x_cw[::-1]
sv_cw = v.cumsum() - x_cw
sv_ccw = v[::-1].cumsum() - x_ccw

imax = sv_cw.argmax()
ans = 0
for i in range(imax+1):
    if i == n-1:
        ans = max(ans, sv_cw[i])
    elif i == n-2:
        ans = max(ans, sv_cw[i] + max(0, (sv_ccw-x_ccw)[:n-i-1]))
    else:
        ans = max(ans, sv_cw[i] + max(0, (sv_ccw-x_ccw)[:n-i-1].max()))

imax = sv_ccw.argmax()
for i in range(imax+1):
    if i == n-1:
        ans = max(ans, sv_ccw[i])
    elif i == n-2:
        ans = max(ans, sv_ccw[i] + max(0, (sv_cw-x_cw)[:n-i-1]))
    else:
        ans = max(ans, sv_ccw[i] + max(0, (sv_cw-x_cw)[:n-i-1].max()))
        
print(int(ans))