N, C = gets.split.map &:to_i
X, V = $<.map{|s|s.split.map &:to_i}.transpose
Vcusum = [sum = 0] + V.map{|v| sum += v }
RVcusum = [sum = 0] + V.reverse.map{|v| sum += v }
RX = X.reverse.map{|x| C - x }

r = (0...N).map{|i|Vcusum[i+1]-Vcusum[0]-X[i]}.max
l = (0...N).map{|i|RVcusum[i+1]-RVcusum[0]-RX[i]}.max
rl = (0...N).map{|i|
  t = Vcusum[i+1]-Vcusum[0]-X[i]
  t.+ (0...N-i-1).map{|j|
    -X[i] + RVcusum[j+1]-RVcusum[0]-RX[j]
  }.max || 0
}.max
lr = (0...N).map{|i|
  t = RVcusum[i+1]-RVcusum[0]-RX[i]
  t.+ (0...N-i-1).map{|j|
    -RX[i] + Vcusum[j+1]-Vcusum[0]-X[j]
  }.max || 0
}.max
p [r, l, rl, lr, 0].max
