import numpy as np
n, c = map(int, input().split())

x_cw = np.empty(n, dtype=np.int64)
v = np.empty(n, dtype=np.int64)
for i in range(n):
    x_cw[i], v[i] = map(np.int64, input().split())

v_cw = v.cumsum(dtype=np.int64) - x_cw
v_cw_r = v_cw - x_cw
x_ccw = c - x_cw[::-1]
v_ccw = v[::-1].cumsum(dtype=np.int64) - x_ccw
v_ccw_r = v_ccw - x_ccw

cw_argmax = v_cw.argmax()
cw_r_argmax = v_cw_r.argmax()
ccw_argmax = v_ccw.argmax()
ccw_r_argmax = v_ccw_r.argmax()

ans = 0
if cw_argmax + ccw_r_argmax < n-1:
    ans = max(ans, v_cw[cw_argmax] + max(v_ccw_r[ccw_r_argmax], 0))
else:
    for i in range(n-ccw_r_argmax-1, cw_argmax+1):
        if n-i-2 < 0:
            ans = max(ans, v_cw[i])
        elif n-i-2 ==0:
            ans = max(ans, v_cw[i] + max(v_ccw_r[n-i-2], 0))
        else:
            ans = max(ans, v_cw[i] + max(v_ccw_r[:n-i-2].max(), 0))

if ccw_argmax + cw_r_argmax < n-1:
    ans = max(ans, v_ccw[ccw_argmax] + max(v_cw_r[cw_r_argmax], 0))
else:
    for i in range(n-cw_r_argmax-1, ccw_argmax+1):
        if n-i-2 < 0:
            ans = max(ans, v_ccw[i])
        elif n-i-2 == 0:
            ans = max(ans, v_ccw[i] + max(v_cw_r[n-i-2], 0))
        else:
            ans = max(ans, v_ccw[i] + max(v_cw_r[:n-i-2].max(), 0))
print(ans)