n,c = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
ans = 0
left = [[0,0]]
right = [[0,0]]
for i in range(n):
    left.append([lis[i][0],left[-1][1]+lis[i][1]])
    right.append([c-lis[-(i+1)][0],right[-1][1]+lis[-(i+1)][1]])
"""
for i in range(n+1):
    for j in range(n-i+1):
          # print(left[i],right[j],left[i][1]+right[j][1]-left[i][0]*2-right[j][0],left[i][1]+right[j][1]-left[i][0]-right[j][0]*2)
        ans = max(ans,left[i][1]+right[j][1]-left[i][0]*2-right[j][0])
        ans = max(ans,left[i][1]+right[j][1]-left[i][0]-right[j][0]*2)
"""
cou = 0
co = 0
num = 0
nu = 0
for i in range(1,n+1):
    if cou < left[i][1]-2*left[i][0]:
        cou = left[i][1]-2*left[i][0]
        num = i
    if co < right[i][1]-2*right[i][0]:
        co = right[i][1]-2*right[i][0]
        nu = i
for j in range(n-num+1):
    ans = max(ans,left[num][1]+right[j][1]-left[num][0]-right[j][0]*2)
for j in range(n-nu+1):
    ans = max(ans,left[j][1]+right[nu][1]-left[j][0]*2-right[nu][0])
print(ans)