N, C = map(int, input().split())
xv = [list(map(int, input().split())) for _ in range(N)]
xv_rev = list(reversed(xv))
xv = [[0,0]]+xv
xv_rev = [[0,0]] + xv_rev
for i in range(1,N+1):
    xv[i] = [xv[i][0],xv[i-1][1]+xv[i][1]+xv[i-1][0]-xv[i][0]]
    xv_rev[i] = [C-xv_rev[i][0],xv_rev[i-1][1]+xv_rev[i][1]+xv_rev[i-1][0]-(C-xv_rev[i][0])]

right = max(xv,key=lambda x:x[1])
left = max(xv_rev,key=lambda x:x[1])
both = 0

for i in range(N+1):
    for j in range(N+1-i):
        both = max(both,xv[i][1]+xv_rev[j][1]-min(xv[i][0],xv_rev[j][0]))

print(max(right[1],left[1],both))
