n,c=gets.split.map(&:to_i)

arr1=[0]
arr2=[0]
arr3=[0]
arr4=[0]

arr=[]

n.times{
    a,b=gets.split.map(&:to_i)
   arr<<[a,b]}
i=0
sum=0
n.times{
    sum+=arr[i][1]
    bb=sum-arr[i][0]
    arr1+=[bb]
    arr3+=[bb-arr[i][0]]
    i+=1}
    
i=0
sum=0
n.times{
    sum+=arr[n-i-1][1]
    
    aa=sum-c+arr[n-i-1][0]
    arr2+=[aa]
     arr4+=[aa-c+arr[n-i-1][0]]
    
    i+=1}    
    
arr5=[]
arr6=[]

j=0
max=0
(n+1).times{
   
       max=[arr1[j],max].max
    arr5<<max
    j+=1
}

j=0
max=0
(n+1).times{
       max=[arr2[j],max].max
  
    arr6<<max
    j+=1}
    
max=(arr1+arr2).max
k=0
(n+1).times{
    
    max=[arr3[k]+arr6[n-k],max].max
k+=1
    
}

k=0
(n+1).times{
    
    max=[arr4[k]+arr5[n-k],max].max
k+=1
    
}


puts max


