n,c=map(int,input().split())
ll,rl=[[0]*2 for _ in range(n+1)],[[0]*2 for _ in range(n+1)]
ls,rs=0,0
xv=[[0,0]]+[list(map(int,input().split())) for _ in range(n)]
for i in range(1,n+1):
    j,k=xv[i]
    rs+=k
    if rl[i-1][1]-rl[i-1][0]<rs-j:
        rl[i][0],rl[i][1]=j,rs
    else:
        rl[i][0],rl[i][1]=rl[i-1][0],rl[i-1][1]
    j,k=xv[n-i+1]
    ls+=k
    ll[i][0],ll[i][1]=(c-j),ls-(c-j)
ans=0
for i in range(n+1):
    ans=max(ans,ll[i][1]+rl[n-i][1]-rl[n-i][0]-min(ll[i][0],rl[n-i][0]))
print(ans)