n,c=map(int,input().split())
rl=[[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
    rl[i][0],rl[i][1]=max(rl[i-1][0],rs-j),max(rl[i-1][1],rs-2*j)
ans=rl[n][0]
for i in range(n):
    ls+=xv[n-i][1]
    ans=max(ans,rl[n-i-1][1]+ls-(c-xv[n-i][0]),rl[n-i-1][0]+ls-(c-xv[n-i][0])*2)
print(ans)