# -*- coding: utf-8 -*-



"""

参考：http://blog.livedoor.jp/misteer/archives/9017497.html

　　　https://www.hamayanhamayan.com/entry/2018/04/21/225805

・累積max(累積和の応用)

・先に回る方向がiより手前にmaxがあったとしても、

　そのパターンは別の周回のiで考慮されているので、

　始点まで戻るマイナス分が多くなっていても問題ない。

　どのみち先に回る方向で最終的にansに採用されるのはiまで行った時のはず。

"""



N, C = list(map(int, input().split()))

x, v = [0], [0]

for i in range(N):

    _x, _v = list(map(int, input().split()))

    x.append(_x)

    v.append(_v)

# 累積max

mx_r = [0] * (N+2)

cal = 0

for i in range(1, N+1):

    cal += v[i] - (x[i] - x[i-1])

    mx_r[i] = max(cal, mx_r[i-1])

mx_l = [0] * (N+2)

cal = v[N] - (C - x[N])

mx_l[N] = cal

for i in range(N-1, 0, -1):

    cal += v[i] - (x[i+1] - x[i])

    mx_l[i] = max(cal, mx_l[i+1])



ans = 0

for i in range(N+1):

    # 右回り→左回り(max(右回りのみ, 逆走もする, 今までの最大))

    ans = max(mx_r[i], mx_r[i] - x[i] + mx_l[i+1], ans)

    # 左回り→右回り

    if i != 0:

        ans = max(mx_l[i], mx_l[i] - (C - x[i]) + mx_r[i-1], ans)

print(ans)

# -*- coding: utf-8 -*-



import sys



def input(): return sys.stdin.readline().strip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = 10 ** 18

MOD = 10 ** 9 + 7



N, C = MAP()

L = [(0, 0)]

for i in range(N):

    x, v = MAP()

    L.append((x, v))

R = [(0, 0)]

for i in range(N, 0, -1):

    x, v = L[i]

    R.append((C-x, v))



# 左右について、片側に進んだ場合の累積max

accL = [0] * (N+1)

cur = 0

for i in range(1, N+1):

    x, v = L[i]

    dist = x - L[i-1][0]

    cur +=  v - dist

    accL[i] = max(accL[i-1], cur)

accR = [0] * (N+1)

cur = 0

for i in range(1, N+1):

    x, v = R[i]

    dist = x - R[i-1][0]

    cur +=  v - dist

    accR[i] = max(accR[i-1], cur)



ans = max(max(accL), max(accR))

# 両側に行く場合を確認

for i in range(N+1):

    # 先に左に行って、戻って右へ

    ans = max(ans, accL[i] - L[i][0] + accR[N-i])

    # 先に右に行って、戻って左へ

    ans = max(ans, accR[i] - R[i][0] + accL[N-i])

print(ans)

# -*- coding: utf-8 -*-
"""
参考：http://blog.livedoor.jp/misteer/archives/9017497.html
　　　https://www.hamayanhamayan.com/entry/2018/04/21/225805
・累積max(累積和の応用)
・先に回る方向がiより手前にmaxがあったとしても、
　そのパターンは別の周回のiで考慮されているので、
　始点まで戻るマイナス分が多くなっていても問題ない。
　どのみち先に回る方向で最終的にansに採用されるのはiまで行った時のはず。
"""
N, C = list(map(int, input().split()))
x, v = [0], [0]
for i in range(N):
    _x, _v = list(map(int, input().split()))
    x.append(_x)
    v.append(_v)
# 累積max
mx_r = [0] * (N + 2)
cal = 0
for i in range(1, N + 1):
    cal += v[i] - (x[i] - x[i - 1])
    mx_r[i] = max(cal, mx_r[i - 1])
mx_l = [0] * (N + 2)
cal = v[N] - (C - x[N])
mx_l[N] = cal
for i in range(N - 1, 0, -1):
    cal += v[i] - (x[i + 1] - x[i])
    mx_l[i] = max(cal, mx_l[i + 1])
ans = 0
for i in range(N + 1):
    # 右回り→左回り(max(右回りのみ, 逆走もする, 今までの最大))
    ans = max(mx_r[i], mx_r[i] - x[i] + mx_l[i + 1], ans)
    # 左回り→右回り
    if i != 0:
        ans = max(mx_l[i], mx_l[i] - (C - x[i]) + mx_r[i - 1], ans)
print(ans)

# -*- coding: utf-8 -*-
import sys


def input():
    return sys.stdin.readline().strip()


def list2d(a, b, c):
    return [[c] * b for i in range(a)]


def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]


def list4d(a, b, c, d, e):
    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]


def ceil(x, y=1):
    return int(-(-x // y))


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST(N=None):
    return list(MAP()) if N is None else [INT() for i in range(N)]


def Yes():
    print("Yes")


def No():
    print("No")


def YES():
    print("YES")


def NO():
    print("NO")


sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, C = MAP()
L = [(0, 0)]
for i in range(N):
    x, v = MAP()
    L.append((x, v))
R = [(0, 0)]
for i in range(N, 0, -1):
    x, v = L[i]
    R.append((C - x, v))
# 左右について、片側に進んだ場合の累積max
accL = [0] * (N + 1)
cur = 0
for i in range(1, N + 1):
    x, v = L[i]
    dist = x - L[i - 1][0]
    cur += v - dist
    accL[i] = max(accL[i - 1], cur)
accR = [0] * (N + 1)
cur = 0
for i in range(1, N + 1):
    x, v = R[i]
    dist = x - R[i - 1][0]
    cur += v - dist
    accR[i] = max(accR[i - 1], cur)
ans = max(max(accL), max(accR))
# 両側に行く場合を確認
for i in range(N + 1):
    # 先に左に行って、戻って右へ
    ans = max(ans, accL[i] - L[i][0] + accR[N - i])
    # 先に右に行って、戻って左へ
    ans = max(ans, accR[i] - R[i][0] + accL[N - i])
print(ans)

-""" -参考：http://blog.livedoor.jp/misteer/archives/9017497.html -　　　https://www.hamayanhamayan.com/entry/2018/04/21/225805 -・累積max(累積和の応用) -・先に回る方向がiより手前にmaxがあったとしても、 -　そのパターンは別の周回のiで考慮されているので、 -　始点まで戻るマイナス分が多くなっていても問題ない。 -　どのみち先に回る方向で最終的にansに採用されるのはiまで行った時のはず。 -""" -N, C = list(map(int, input().split())) -x, v = [0], [0] +import sys + + +def input(): +    return sys.stdin.readline().strip() + + +def list2d(a, b, c): +    return [[c] * b for i in range(a)] + + +def list3d(a, b, c, d): +    return [[[d] * c for j in range(b)] for i in range(a)] + + +def list4d(a, b, c, d, e): +    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] + + +def ceil(x, y=1): +    return int(-(-x // y)) + + +def INT(): +    return int(eval(input())) + + +def MAP(): +    return list(map(int, input().split())) + + +def LIST(N=None): +    return list(MAP()) if N is None else [INT() for i in range(N)] + + +def Yes(): +    print("Yes") + + +def No(): +    print("No") + + +def YES(): +    print("YES") + + +def NO(): +    print("NO") + + +sys.setrecursionlimit(10**9) +INF = 10**18 +MOD = 10**9 + 7 +N, C = MAP() +L = [(0, 0)] -    _x, _v = list(map(int, input().split())) -    x.append(_x) -    v.append(_v) -# 累積max -mx_r = [0] * (N + 2) -cal = 0 +    x, v = MAP() +    L.append((x, v)) +R = [(0, 0)] +for i in range(N, 0, -1): +    x, v = L[i] +    R.append((C - x, v)) +# 左右について、片側に進んだ場合の累積max +accL = [0] * (N + 1) +cur = 0 -    cal += v[i] - (x[i] - x[i - 1]) -    mx_r[i] = max(cal, mx_r[i - 1]) -mx_l = [0] * (N + 2) -cal = v[N] - (C - x[N]) -mx_l[N] = cal -for i in range(N - 1, 0, -1): -    cal += v[i] - (x[i + 1] - x[i]) -    mx_l[i] = max(cal, mx_l[i + 1]) -ans = 0 +    x, v = L[i] +    dist = x - L[i - 1][0] +    cur += v - dist +    accL[i] = max(accL[i - 1], cur) +accR = [0] * (N + 1) +cur = 0 +for i in range(1, N + 1): +    x, v = R[i] +    dist = x - R[i - 1][0] +    cur += v - dist +    accR[i] = max(accR[i - 1], cur) +ans = max(max(accL), max(accR)) +# 両側に行く場合を確認 -    # 右回り→左回り(max(右回りのみ, 逆走もする, 今までの最大)) -    ans = max(mx_r[i], mx_r[i] - x[i] + mx_l[i + 1], ans) -    # 左回り→右回り -    if i != 0: -        ans = max(mx_l[i], mx_l[i] - (C - x[i]) + mx_r[i - 1], ans) +    # 先に左に行って、戻って右へ +    ans = max(ans, accL[i] - L[i][0] + accR[N - i]) +    # 先に右に行って、戻って左へ +    ans = max(ans, accR[i] - R[i][0] + accL[N - i])