n,c=gets.split.map &:to_i
x,v=($<.map{|l|l.split.map(&:to_i)}).transpose
y=[];x.each{|e|y.unshift(c-e)}
x.unshift(0);y.unshift(0)
r=[0];l=[0]
v.each{|e|r<<r[-1]+e}
(v.reverse).each{|e|l<<l[-1]+e}

m=0
for i in 0..n
  for j in 0..n-i
    s=r[i]+l[j]-x[i]-2*y[j]
    m=s if m<s
    s=r[i]+l[j]-2*x[i]-y[j]
    m=s if m<s
  end
end
p m
    