N,C=map(int,input().split())
x=[0 for i in range(N)]
v=[0 for i in range(N)]
for i in range(N):
    x[i],v[i]=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
a[0]=v[0]
b[N-1]=v[N-1]
for i in range(1,N):
    a[i]=v[i]+a[i-1]
for i in range(N-1)[::-1]:
    b[i]=b[i+1]+v[i]
ans=0
for i in range(N+1):
    for j in range(N-i+1):
        if i==0:
            OA=0
            EA=0
        else:
            OA=x[i-1]
            EA=a[i-1]
        if j==0:
            OB=0
            EB=0
        else:
            OB=C-x[N-j]
            EB=b[N-j]
        tmpA=EA+EB-OA-OA-OB
        tmpB=EA+EB-OA-OB-OB
        if ans<tmpA:
            ans=tmpA
        if ans<tmpB:
            ans=tmpB
print(ans)
