n,c = map(int,input().split())
x = []
v = []
f = []
g = []
dis = 0
for i in range(0,n):
    X,V = map(int,input().split())
    x.append(X)
    v.append(V)
    if i == 0:
        f.append(v[i]-x[i])
        dis = X
        g.append((max(f),dis))
        continue
    f.append(f[i-1]+v[i]-x[i]+x[i-1])
    if f[i] > max(f[0:i]):
        dis = X
    g.append((max(f),dis))
ans = 0
vb = 0
for b in range(n-1,0,-1):
    va , da = g[b-1]
    dis = min((c-x[b]) , da)
    ans = max(ans,vb + v[b]-(c-x[b]) + va - dis)
    vb += v[b]
ans = max(ans,vb + v[0] - (c-x[0]))
va , da = g[n-1]
ans = max(ans,va)
print(ans)
