N, C = gets.split.map(&:to_i)

xs, vs = [], []
N.times do |i|
    xs[i], vs[i] = gets.split.map(&:to_i)
end

max = 0

max_cw = Array.new(N, 0)
max_ccw = Array.new(N, 0)
ret_max_cw = Array.new(N, 0)
ret_max_ccw = Array.new(N, 0)

sum = vs[0] - xs[0]
max_cw[0] = [sum, 0].max
sum2 = vs[0] - 2 * xs[0]
ret_max_cw[0] = [sum2, 0].max
(N - 1).times do |i|
    sum += vs[i+1] - (xs[i+1] - xs[i])
    sum2 += vs[i+1] - (xs[i+1] - xs[i]) * 2
    max_cw[i+1] = [max_cw[i], sum].max
    ret_max_cw[i+1] = [ret_max_cw[i], sum2].max
end

sum = vs[-1] - (C - xs[-1])
max_ccw[-1] = [sum, 0].max
sum2 = vs[-1] - (C - xs[-1]) * 2
ret_max_ccw[-1] = [sum2, 0].max
(N - 1).times do |i|
    sum += vs[N - 2 - i] - (xs[N - 1 - i] - xs[N - 2 - i])
    sum2 += vs[N - 2 - i] - (xs[N - 1 - i] - xs[N - 2 - i]) * 2
    max_ccw[N - 2 - i] = [max_ccw[N - 1 - i], sum].max
    ret_max_ccw[N - 2 - i] = [ret_max_ccw[N - 1 - i], sum2].max
end

ans = [max_cw.max, max_ccw.max].max
(N - 2).times do |i|
    cal = [
        ret_max_cw[i] + max_ccw[i+1],
        ret_max_ccw[i+1] + max_cw[i]
    ].max
    ans = cal if ans < cal
end

puts ans