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

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

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

    ans = max(ans, ans1 + ans2)

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

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

    ans = max(ans, ans1 + ans2)

print(ans)
