N, C = map(int, input().split())
sushi = []
for i in range(N):
    sushi.append(list(map(int, input().split())))

right_turn_sum = [0]
for i in range(N):
    right_turn_sum.append(sushi[i][1]+right_turn_sum[i])
for i in range(N):
    right_turn_sum[i+1] -= sushi[i][0]
right_turn_to_zero = [0]
for i in range(N):
    right_turn_to_zero.append(right_turn_sum[i+1]-sushi[i][0])

left_turn_sum = [0]
for i in range(N):
    left_turn_sum.append(sushi[-1-i][1]+left_turn_sum[i])
for i in range(N):
    left_turn_sum[i+1] -= (C - sushi[-1-i][0])
left_turn_to_zero = [0]
for i in range(N):
    left_turn_to_zero.append(left_turn_sum[i+1]-(C-sushi[-1-i][0]))


ans = max(right_turn_sum)
ans = max(left_turn_sum+[ans])

maxi = 0
for i in range(N+1):
    if maxi < right_turn_sum[i]:
        maxi = right_turn_sum[i]
    right_turn_sum[i] = max(maxi, right_turn_sum[i])

maxi = 0
for i in range(N+1):
    if maxi < right_turn_to_zero[i]:
        maxi = right_turn_to_zero[i]
    right_turn_to_zero[i] = max(maxi, right_turn_to_zero[i])

maxi = 0
for i in range(N+1):
    if maxi < left_turn_sum[i]:
        maxi = left_turn_sum[i]
    left_turn_sum[i] = max(maxi, left_turn_sum[i])

maxi = 0
for i in range(N+1):
    if maxi < left_turn_to_zero[i]:
        maxi = left_turn_to_zero[i]
    left_turn_to_zero[i] = max(maxi, left_turn_to_zero[i])


for i in range(N+1):
    ans = max(ans, right_turn_to_zero[i]+left_turn_sum[N-i])

for i in range(N+1):
    ans = max(ans, left_turn_to_zero[i]+right_turn_sum[N-i])
print(ans)
