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

I = np.zeros((N+1, N+1))

I[0, 0] = 0
I[0, N] = v_list[N-1] - (C - x_list[N-1])

for k in range(0, N):
    if k == 0:
        I[k+1, 0] = I[k, 0] + v_list[k] - x_list[k]
    elif k > 0:
        I[k+1, 0] = I[k, 0] + v_list[k] - (x_list[k] - x_list[k-1])

for l in reversed(range(2, N+1)):
    if l > 0:
        I[0, l-1] = I[0, l] + v_list[l-2] -(x_list[l-1] - x_list[l-2])

for k in range(1, N+1):
    for l in range(k+1, N+1):
        if k > 1:
            I[k, l] = I[k - 1, l] + v_list[k-1] - 2 * (x_list[k-1] - x_list[k-2])
        elif k == 1:
            I[k, l] = I[k - 1, l] + v_list[k-1] - 2 * (x_list[k-1])

M = max(I)
print(M)
