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


fAs = [0] * N
fAs[0] = vs[0]
for A in range(1, N):
    fAs[A] = fAs[A - 1] + vs[A]
for A in range(N):
    fAs[A] -= xs[A]

gAs = [0] * N
gAs[0] = 0
for A in range(1, N):
    gAs[A] = max(gAs[A - 1], fAs[A - 1])


fBs = [0] * N
fBs[N - 1] = vs[N - 1]
for B in range(0, N - 1)[::-1]:
    fBs[B] = fBs[B + 1] + vs[B]

for B in range(N):
    fBs[B] -= C - xs[B]

gBs = [0] * N
gBs[N - 1] = 0
for B in range(0, N - 1)[::-1]:
    gBs[B] = max(gBs[B + 1], fBs[B + 1])


ans = 0

# 初手：時計回り
for A in range(N):
    ans1 = fAs[A]

    # 2手目：反時計回り
    ans2 = max(0, gBs[A] - xs[A])

    ans = max(ans, ans1 + ans2)


# 初手：反時計回り
for B in range(N):
    ans1 = fBs[B]

    # 2手目：時計回り
    ans2 = max(0, gAs[B] - (C - xs[B]))

    ans = max(ans, ans1 + ans2)

print(ans)
