n, c= gets.split(' ').map(&:to_i)
tr = [0] # indexは1から
tr2 = [0]# indexは1から
tl = [0] # indexは1から
tl2 = [0]# indexは1から
poss = []
cals = []
(0..n-1).each do |i|
  pos, cal = gets.split(' ').map(&:to_i)
  poss << pos
  cals << cal
  tr << tr[-1] + cal - pos
  tr2 << tr2[-1] + cal - pos * 2
end

(0..n-1).each do |i|
  pos, cal = [c- poss[n-1-i], cals[n-1-i]]
  
  tl << tl[-1] + cal - pos
  tl2 << tl2[-1] + cal - pos * 2
end

tlm = tl.max
trm = tr.max

tlm_index = tl.index(tlm) 
trm_index = tr.index(trm)

puts tl2.to_s
puts tr2.to_s
puts n
puts n-tlm_index
puts n-trm_index

tl2m = tl2[0..n-trm_index+1].max
puts tl2[0..n-trm_index+1].to_s
tr2m = tr2[0..n-tlm_index+1].max
puts [tlm, tl2m, trm, tr2m].to_s

total = [tlm+tr2m, trm+tl2m, trm, tlm]
puts total.to_s
print total.max
