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

if N == 1:
    x, v = map(int, input().split())
    print(max(0, v-x, v-(C-x)))
    exit()


Cost = [] #[x, v, left_cumsum, left_cummax, right_cumsum, right_cummax]

cum = 0
x, v = map(int, input().split())
cum += v
Cost.append([x, v, cum-x, max(0, cum-x), 0, 0])
for _ in range(N-1):
    x, v = map(int, input().split())
    cum += v
    Cost.append([x, v, cum-x, max(Cost[-1][3], cum-x), 0, 0])

cum = 0
cum += Cost[-1][1]
Cost[-1][4] = cum - (C - Cost[-1][0])
Cost[-1][5] = max(0, Cost[-1][4])
for i in range(N-2, -1, -1):
    cum += Cost[i][1]
    Cost[i][4] = cum - (C - Cost[i][0])
    Cost[i][5] = max(Cost[i+1][5], Cost[i][4])
    
max_val = 0
max_val = max(max_val, Cost[0][3], Cost[0][5],\
        Cost[0][2] + Cost[1][5] - Cost[0][0])
max_val = max(max_val, Cost[-1][3], Cost[-1][5],\
        Cost[-1][4] + Cost[-2][3] - (C-Cost[-1][0]))
for i in range(1, N-1):
    max_val = max(max_val, Cost[i][3], Cost[i][5],\
            Cost[i][2] + Cost[i+1][5] - Cost[i][0],\
            Cost[i][4] + Cost[i-1][3] - (C-Cost[i][0]))

print(max_val)
