n,c = gets.chomp.split(" ").map(&:to_i)
x = n.times.map{gets.chomp.split(" ").map(&:to_i)}.sort_by{|i,j|i}
y = Marshal.load(Marshal.dump(x))
rx,ry = 2.times.map{Array.new(n+1,0)}
ans = 0
temp = 0
y.reverse!
for i in 0..n-1
  y[i][0] = c-y[i][0]
end
x.unshift([0,0])
y.unshift([0,0])
for i in 1..n
  x[i][1] += x[i-1][1]
  y[i][1] += y[i-1][1]
  rx[i] = x[i][1]-2*x[i][0]
  ry[i] = y[i][1]-2*y[i][0]
end
for i in 0..n
  temp = y[i][1]-y[i][0]+rx[0..n-i].max
  ans = [temp,ans].max
  temp = x[i][1]-x[i][0]+ry[0..n-i].max
  ans = [temp,ans].max
end
puts ans