N, C = map(int,input().split())
x=["" for i in range(N)]
v=["" for i in range(N)]


for i in range(N):
    x[i], v[i] = map(int,input().split())

x=[0]+x
v=[0]+v

Cal=[0 for i in range((N+2)**2)]
ind=0

for R in range(N+1):
    for L in range(N-R+1):
        if R==0:
            CalR=0
        else:
            CalR=sum(v[:R+1])-x[R]
        
        if L==0:
            CalL=0
            d=0
        else:
            CalL=sum(v[N-L+1:])-(C-x[N-L+1])
            d=C-x[N-L+1]
        
        Cal[ind]=max(CalR+CalL-x[R],CalR+CalL-d)
        ind=ind+1

print(max(Cal))
