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}
f=[0];g=[0]
for k in 1...n
  f<<[f[-1],r[k]-x[k]].max
  g<<[f[-1],r[k]-2*x[k]].max
end

m=0
for i in 0..n
  m=[l[i]-y[i]+g[n-i],l[i]-2*y[i]+f[n-i],m].max
end
p m