n,c=map(int,input().split())
ll,rl=[0]*(n+1),[0]*(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]=rs-j
    j,k=xv[n-i+1]
    ls+=k
    ll[i]=ls-(c-j)
ans=0
for l in range(n+1):
    for r in range(n-l):
        if ll[l]<0:
            continue
        if rl[r]<0:
            continue
        if l==0 or r==0:
            ans=max(ans,ll[l]+rl[r])
        else:
            ans=max(ans,ll[l]+rl[r]-min(c-xv[n-l-1][0],xv[r][0]))
print(ans)