n,c = map(int,input().split())
xv = [ tuple(map(int, input().split())) for _ in range(n)]

go = [[0] * (n+1) for _ in range(2)]
turn = [[0] * (n+1) for _ in range(2)]

tmp = 0
g_max = 0
t_max = 0
for i in range(1,n+1):
    tmp += xv[i-1][1]
    go[0][i] = g_max = max(tmp - xv[i-1][0], g_max)
    turn[0][i] = t_max = max(tmp - xv[i-1][0] * 2, t_max)
    
tmp = 0
g_max = 0
t_max = 0
for i in range(n, 0, -1):
    tmp += xv[i-1][1]
    go[1][i] = g_max = max(tmp - (c - xv[i-1][0]), g_max)
    turn[1][i] = t_max = max(tmp - (c - xv[i-1][0]) * 2, t_max)

ans = 0
for i in range(1, n+1):
    ans = max(go[0][i] + turn[1][(i+1)%(n+1)], ans)
    ans = max(go[1][i] + turn[0][i-1], ans)
    
print(ans)