n,c=[int(k) for k in raw_input().split(" ")]
t=[]
for i in range(n):
    t+=[tuple([int(k) for k in raw_input().split(" ")])]

ts=sorted(t)
tot=sum([k[1] for k in t])
maxperf=0
mysum=0
mpcw=[0]*n
mpccw=[0]*n
mpcwab=[0]*n
mpccwab=[0]*n

k=0
for i in ts:
    mpccw[k]=tot-mysum - (c-i[0])
    mpccwab[k]=tot-mysum - (c-i[0])*2
    mysum+=i[1]
    mpcw[k]=mysum-i[0]
    mpcwab[k]=mysum-i[0]*2
    k+=1
    
#runningmaxes
 
mpucw=[0]*(n)
mpuccw=[0]*(n)

for i in range(0,n):
    mpucw[i]=max(mpucw[i-1],mpcwab[i]) #best i can get reaching < guy i cw then coming back
    

for i in range(-1,-n-1,-1):
    mpuccw[i]=max(mpuccw[i+1],mpccwab[i]) #best i can get reaching < guy i cw then coming back
    
for i in range(n):
    maxperf=max(maxperf, mpcw[i] + (mpuccw[i+1] if i<n-1 else 0) )
    maxperf=max(maxperf, mpccw[i] + (mpucw[i-1] if i>0 else 0) )

print maxperf