N, C = gets.split.map(&:to_i)
xs = [0]
vs = [0]
N.times do 
  x, v = gets.split.map(&:to_i)
  xs << x
  vs << v
end
X = xs
V = vs

right_col = [0]
left_col = [0]
for i in 1..N
  col = right_col[i-1] - (xs[i]-xs[i-1]) + vs[i]
  right_col << col

  d = xs[-i+1]
  if d==0
    d = C
  end

  col = left_col[i-1] - (d-xs[-i]) + vs[-i]
  left_col << col
end

max_sushi = 0
max_sushi = [max_sushi, right_col.max].max
max_sushi = [max_sushi, left_col.max].max

for r in 1..N
  for l in 1..(N-r)
    w = right_col[r] - xs[r] + left_col[l]
    max_sushi = [max_sushi, w].max
  end
end
for l in 1..N
  for r in 1..(N-l)
    w = left_col[l] - (C-xs[-l]) + right_col[r]
    max_sushi = [max_sushi, w].max
  end
end
puts max_sushi

