N, C = map(int, input().split())
X = []; V = []
for i in range(N):
    x, v = map(int, input().split())
    X.append(x); V.append(v)
P0 = []; P1 = []
ma0 = cu0 = ma1 = cu1 = 0
pos = 0
for i in range(N):
    cu0 += V[i]-(X[i]-pos)
    cu1 += V[i]-(X[i]-pos)*2
    ma0 = max(ma0, cu0)
    ma1 = max(ma1, cu1)
    P0.append(ma0)
    P1.append(ma1)
    pos = X[i]
Q0 = []; Q1 = []
ma0 = cu0 = ma1 = cu1 = 0
pos = C
for i in range(N):
    cu0 += V[-i-1]-(pos-X[-i-1])
    cu1 += V[-i-1]-(pos-X[-i-1])*2
    ma0 = max(ma0, cu0)
    ma1 = max(ma1, cu1)
    Q0.append(ma0)
    Q1.append(ma1)
    pos = X[-i-1]
ans = max(P0[N-1], Q0[N-1])
for i in range(N-1):
    ans = max(ans, P0[i] + Q1[-i-2], P1[-i-2] + Q0[i])
print(ans)
