
N,C = map(int,input().split())

xv = []

for i in range(N):

    x,v = map(int,input().split())
    xv.append([x,v])

xv.sort()

ldis = [0]
lcal = [0]

for i in range(N):

    ldis.append(xv[i][0])
    lcal.append(lcal[-1] + xv[i][1])

lmax = [0]
for i in range(N):
    i += 1
    lmax.append( max(lmax[-1] , lcal[i] - ldis[i]) )

rdis = [0]
rcal = [0]

for i in range(N):
    i = N-1-i
    rdis.append(C - xv[i][0])
    rcal.append(rcal[-1] + xv[i][1])

rmax = [0]
for i in range(N):
    i += 1
    rmax.append ( max(rmax[-1] , rcal[i] - rdis[i]) )

lmax2 = [0]
for i in range(N):
    i += 1
    lmax2.append( max(lmax2[-1] , lcal[i] - ldis[i] * 2) )
rmax2 = [0]
for i in range(N):
    i += 1
    rmax2.append ( max(rmax2[-1] , rcal[i] - rdis[i] * 2) )

ans = 0
for i in range(N+1):

    if i != N-i:
        ans = max(ans,lmax[i] + rmax2[N-i],lmax2[i] + rmax[N-i])

#print (lmax,lmax2,rmax,rmax2)
print (ans)