import numpy as np

N, C = map(int, input().split())
x_list = []
v_list = []
for i in range(0, N):
    x, v = map(int, input().split())
    x_list.append(x)
    v_list.append(v)

# 右行って左に引き返す

a_list = [0]

for i in range(0, len(v_list)):
    if i > 0:
        l = a_list[i] + v_list[i] - (x_list[i] - x_list[i - 1])
        a_list.append(l)
    elif i == 0:
        l = v_list[i] - (x_list[i])
        a_list.append(l)

a_accum_max = [max(a_list[:x+1]) for x in range(0, len(a_list))]


b_list = [0]

for i in reversed(range(0, len(v_list))):
    if i == N-1:
        l = v_list[i] - 2 * (C - x_list[i])
        b_list.append(l)
    elif i < N-1:
        l = b_list[N - i - 1] + v_list[i] - 2 * (x_list[i+1] -x_list[i])
        b_list.append(l)

first_list = []
for i in range(0, len(b_list)):
    first_list.append(a_accum_max[N-i] + b_list[i])

max_fir = max(first_list)

# 左行って右に引き返す
# 
# c_list = [0]
# 
# for i in range(0, len(v_list)):
#     if i > 0:
#         l = c_list[i] + v_list[i] - 2 * (x_list[i] - x_list[i - 1])
#         c_list.append(l)
#     elif i == 0:
#         l = v_list[i] - 2 * (x_list[i])
#         c_list.append(l)
# 
# c_accum_max = [max(c_list[:x+1]) for x in range(0, len(c_list))]
# 
# d_list = [0]
# 
# for i in reversed(range(0, len(v_list))):
#     if i == N-1:
#         l = v_list[i] - (C - x_list[i])
#         d_list.append(l)
#     elif i < N-1:
#         l = d_list[N - i - 1] + v_list[i] - (x_list[i+1] -x_list[i])
#         d_list.append(l)
# 
# second_list = []
# for i in range(0, len(d_list)):
#     second_list.append(c_accum_max[N-i] + d_list[i])

# max_sec = max(second_list)
max_num = max([max_fir, 0])
print(max_num)