# Generated by AtcoderGreedy on 2018-04-21
# ARC096 D
# Your code here

# require 'pry-byebug'
# require 'pry'

def input_args
  n, c = gets.chomp.split(' ').map(&:to_i)
  sushis = []
  n.times do
    sushis << gets.chomp.split(' ').map(&:to_i)
  end
  [n, c, sushis]
end

# N, C, sushis = [
#   3, 20,
#   [[2, 80],
#    [9, 1],
#    [16, 120]]
# ]

N, C, sushis = input_args

class Range
  def &(other)
    a = to_closed
    b = other.to_closed
    ([a.first, b.first].max..[a.last, b.last].min)
  end

  def to_closed
    return self unless exclude_end?
    (first..(last - 1))
  end

  def superset_of?(other)
    a = to_closed
    b = other.to_closed
    a.first <= b.first && a.last >= b.last
  end

  def subset_of?(other)
    other.superset_of? self
  end

  def empty?
    !(any? { |_| true })
  end
end

def candidates(sushis)
  candidates = [[0, 0]]
  sushis.each do |x, v|
    prev_x, prev_v = candidates.last
    candidates << [x, prev_v + v - (x - prev_x)]
  end
  candidates.map { |x| x[1] }
end

sushis2 = sushis.map { |x, v| [C - x, v] }.sort

cands1 = candidates(sushis)
cands2 = candidates(sushis2)

class SegTree
  def initialize(arr, reducer)
    ret = [arr]
    l = arr.size
    l /= 2
    while l > 0
      cand = []
      prev = ret.last
      l.times do |i|
        cand << reducer.call(prev[2*i], prev[2*i+1])
      end
      ret << cand
      l /= 2
    end
    @tree = ret
    @reducer = reducer
  end

  def cover_of(h, i)
    l = 2**h
    (l * i)..(l * (i + 1) - 1)
  end

  def reduced_value_of_sub(h, range, i = 0)
    h_range = cover_of h, i
    return nil if (range & h_range).empty?
    return @tree[h][i] if range.superset_of? h_range
    cand1 = reduced_value_of_sub(h-1, range, i*2)
    cand2 = if i*2+1 < @tree[h-1].size
              reduced_value_of_sub(h-1, range, i*2+1)
            end
    cands = [cand1, cand2].reject(&:nil?)
    return nil if cands.empty?
    cands.reduce(&@reducer)
  end

  def value_of(range)
    range = range.to_closed
    h = log2_ceil(range.last + 1)
    reduced_value_of_sub(h, range)
  end

  def log2_ceil(n)
    n = n.to_i
    ret = 0
    while n > 0
      n /= 2
      ret += 1
    end
    ret
  end
end

max_proc = ->(*args) { args.max }

seg1 = SegTree.new cands1, max_proc
seg2 = SegTree.new cands2, max_proc

def find_best(sushis, counter_seg)
  current = 0
  prev_x = 0
  candidate = 0
  (N-1).times do |i|
    x, v = sushis[i]
    current += v - (x - prev_x)
    hoge = counter_seg.value_of(0...(N - i))
    candidate = [
      candidate,
      (hoge - x) + current
    ].max
    prev_x = x
  end
  candidate
end

# binding.pry

puts [
  find_best(sushis, seg2),
  find_best(sushis2, seg1),
  seg1.value_of(0..N),
  seg2.value_of(0..N)
].max
