n,c = map(int,input().split())
x = [0]
v = [0]
f = [0] * (n+1)
g = [(0,0)] * (n+1)
dis = 0
for i in range(0,n):
    X,V = map(int,input().split())
    x.append(X)
    v.append(V)
for i in range(0,n):
    f[i+1] = f[i] + v[i+1]
    rv,rd = g[i]
    if f[i+1] - x[i+1] > rv:
        dis = x[i+1]
    g[i+1] = (max(rv,f[i+1] - x[i+1]),dis)

rv,rd = g[n]
ans = max(0,rv)
lv = 0
for b in range(n,0,-1):
    rv,rd = g[b-1]
    lv += v[b]
    dis = min(rd,(c-x[b]))
    ans = max(ans,rv + lv - (c-x[b]) - dis)
print(ans)
