n,c = gets.chomp.split(" ").map(&:to_i)
xv = n.times.map{gets.chomp.split(" ").map(&:to_i)}.sort_by{|i,j|i}
#p xv
f = xv.unshift([0,0]).rindex{|i,j|i <= c/2}
a = xv[0..f]
b = xv[f+1..-1].push([c,0])
ans = 0
temp = 0
xv.unshift([0,0])
for i in 1..n
  temp -= xv[i][0]-xv[i-1][0]
  temp += xv[i][1]
  ans = [ans,temp].max
end
for i in 0..b.size-1
  b[i][0] = c-b[i][0]
end
b.reverse!
#p a,b
af = 0
bf = 0
temp = 0
for i in 1..a.size-1
  temp -= a[i][0]-a[i-1][0]
  temp += a[i][1]
  af = [af,temp].max
end
temp = 0
for i in 1..b.size-1
  temp -= b[i][0]-b[i-1][0]
  temp += b[i][1]
  bf = [bf,temp].max
end
temp = 0
au = 0
for i in 1..a.size-1
  temp -= (a[i][0]-a[i-1][0])*2
  temp += a[i][1]
  au = [au,temp].max
end
temp = 0
bu = 0
for i in 1..b.size-1
  temp -= (b[i][0]-b[i-1][0])*2
  temp += b[i][1]
  bu = [bu,temp].max
end
#p ans,au,af,bu,bf
ans = [ans,au+bf,bu+af,0].max
puts ans