N, C = map(int, input().split())
xs = []
vs = []
for i in range(N):
    x, v = map(int, input().split())
    xs += [x]
    vs += [v]

sumVtos = [vs[0]]
for i in range(1, N):
    sumVtos += [sumVtos[-1] + vs[i]]

sumV = sumVtos[-1]
sumVfrs = [sumV]
for i in range(1, N):
    sumVfrs += [sumVfrs[-1] - vs[i - 1]]

# 初手：時計回り
ans = 0
for i in range(N):
    ans1 = sumVtos[i] - xs[i]

    # 2手目：反時計回り
    ans2 = 0
    for j in range(i + 1, N):
        ans2 = max(ans2, sumVfrs[j] - (xs[i] + C - xs[j]))

    ans = max(ans, ans1 + ans2)

# 初手：反時計回り
for i in range(N):
    ans1 = sumVfrs[i] - (C - xs[i])

    # 2手目：時計回り
    ans2 = 0
    for j in range(i):
        ans2 = max(ans2, sumVtos[j] - (C - xs[i] + xs[j]))

    ans = max(ans, ans1 + ans2)

print(ans)
