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

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)

maxtotal=0
#時計回りの場合
for i in range(n,0,-1):
    if i < n:
        x.insert(0,x[n-1]-c)
        v.insert(0,v[n-1])
    tmp=eval_cal(x,v,n)
    if tmp > maxtotal:
        maxtotal=tmp

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

for i in range(n,0,-1):
    if i < n:
        x.insert(0,x[n-1]-c)
        v.insert(0,v[n-1])
    tmp=eval_cal(x,v,n)
    if tmp > maxtotal:
        maxtotal=tmp

print(maxtotal)

