#!python
# -*- coding: utf-8 -*-


N, C = list(map(int, input().split(' ')))
X = []
V = []
for n in range(N):
    X_, V_ = list(map(int, input().split(' ')))
    X.append(X_)
    V.append(V_)

P = [0] + X + [C]

R_sushi_sum = [0]
L_sushi_sum = [0]
for i in range(N):
    R_sushi_sum.append(V[i] + R_sushi_sum[i])
    L_sushi_sum.append(V[-1 - i] + L_sushi_sum[i])

ANS = 0

for a in range(len(P) - 1):
    OA = P[a]
    SUSHI = R_sushi_sum[a]
    v = SUSHI - OA
    ANS = max(ANS, v)

for b in range(len(P) - 1):
    OB = C - P[-1 - b]
    SUSHI = L_sushi_sum[b]
    v = SUSHI - OB
    ANS = max(ANS, v)

for a in range(len(P) - 1):
    for b in range(a + 1, len(P) - 1):
        OA = P[a]
        OB = C - P[b]
        SUSHI = R_sushi_sum[a] + L_sushi_sum[len(P) - 1 - b]
        v_a = SUSHI - (OA * 2 + OB)
        v_b = SUSHI - (OA + OB * 2)
        ANS = max(ANS, v_a, v_b)

print(ANS)
