def eval_cal(x,v,n):
    tmp=0
    maxtotal=0
    for i in range(n):
        if i ==0:
            dis=abs(x[0])
        else :
            dis=x[i]-x[i-1]
    
        tmp+=v[i]-dis
        #print(tmp)
        if tmp > maxtotal:
            maxtotal=tmp
            
    return maxtotal

def setup_cal(x,v,n):
    tmp=0
    maxtotal=0
    maxx=0
    vm=[]
    xm=[]
    #print("x:",x)
    #print("v:",v)
    for i in range(n):
        if i ==0:
            dis=abs(x[0])
        else :
            dis=x[i]-x[i-1]
    
        tmp+=v[i]-dis
        #print(tmp)
        if tmp > maxtotal:
            maxtotal=tmp
            maxx=x[i]
        xm.append(maxx)
        vm.append(maxtotal)
        #print(x[i],maxtotal)
    return xm,vm
    

n, c = map(int,input().split(' '))
x=[]
v=[]
for i in range(n):
    xt,vt = map(int,input().split(' '))
    x.append(xt)
    v.append(vt)

xm1, vm1=setup_cal(x,v,n)
#print(xm1,vm1)
#反時計回りの場合
#設定
x.reverse()
v.reverse()
for i in range(n):
    x[i]=c-x[i]

xm2, vm2=setup_cal(x,v,n)
#print(xm2,vm2)

maxtotal=0

for i in range(n):
    if i == 0:
        tmp = vm1[0]
    elif i == n-1:
        tmp = vm2[n-1]
    else:
        tmp = vm1[i]+vm2[i-1]-xm1[i-1]
    #print(tmp)
    if maxtotal < tmp:
        maxtotal=tmp

print(maxtotal)