n,c = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]

rcur = 0
lcur = 0
rmax = 0
lmax = 0
r = [[0,0]]
for i in range(n):
    a,b = x[i]
    rcur += b
    lcur = a
    if rmax < rcur-lcur:
        rmax = rcur-lcur
        lmax = lcur
    r.append([rmax,lmax])

rcur = 0
lcur = 0
rmax = 0
lmax = 0
l = [[0,0] for i in range(n+1)]
for i in range(1,n+1):
    a,b = x[-i]
    rcur += b
    lcur = c-a
    if rmax < rcur-lcur:
        rmax = rcur-lcur
        lmax = lcur
    l[-1-i] = [rmax,lmax]


ans = 0

for i in range(n+1):
    count = l[i][0]+r[i][0] - min(l[i][1],r[i][1])
    ans = max(ans,count)
    
print(ans)

