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))
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]
end
for i in 0..n
  for j in 0..n-i
    temp = y[i][1]-y[i][0]+x[j][1]-2*x[j][0]
    ans = [temp,ans].max
    temp = x[i][1]-x[i][0]+y[j][1]-2*y[j][0]
    ans = [temp,ans].max
  end
end
puts ans