n, c = gets.split.map(&:to_i)
exit if n > 200
xs = []
vs = []
vsum = 0
n.times {
  x, v = gets.split.map(&:to_i)
  xs << x
  vs << v
  vsum += v
}

cw = []
ccw = []

ac = 0
cur = 0
n.times do |i|
  x = xs[i]
  v = vs[i]
  ac += v - (x - cur)
  cur = x
  cw << ac
end

ac = 0
cur = 0
n.times do |i|
  x = c - xs[n - 1 - i]
  v = vs[n - 1 - i]
  ac += v - (x - cur)
  cur = x
  ccw << ac
end

ans = [0, cw.max, ccw.max].max

(n - 1).times do |i|
  ans = [ans, cw[i] - xs[i] + (n - i - 1).times.map {|j| ccw[j]}.max].max
  ans = [ans, ccw[i] - (c - xs[n-1-i]) + (n - i - 1).times.map {|j| cw[j]}.max].max
end

p ans
