n,c = gets.split.map(&:to_i)
x = []
v = []

r_max = 0
r_max_arr = []
r_back_max = 0
r_back_max_arr = []

r_sum = 0
n.times do |i|
  x[i],v[i] = gets.split.map(&:to_i)
  r_sum += v[i]
  if r_max < r_sum - x[i]
    r_max = r_sum - x[i]
  end
  if r_back_max < r_sum - 2*x[i]
    r_back_max = r_sum - 2*x[i]
  end
  r_max_arr[i] = r_max
  r_back_max_arr[i] = r_back_max
end

l_max = 0
l_max_arr = []
l_back_max = 0
l_back_max_arr = []

l_sum = 0
n.times do |i|
  l_sum += v[(n-1)-i]
  if l_max < l_sum - (c-x[(n-1)-i])
    l_max = l_sum - (c-x[(n-1)-i])
  end
  if l_back_max < l_sum - 2*(c-x[(n-1)-i])
    l_back_max = l_sum - 2*(c-x[(n-1)-i])
  end
  l_max_arr[(n-1)-i] = l_max
  l_back_max_arr[(n-1)-i] = l_back_max
end

max = 0
if n == 1
  max = [r_max_arr[0],l_max_arr[0]].max
else
  (n-1).times do |i|
    if max < r_max_arr[i]+l_back_max_arr[i+1]
      max = r_max_arr[i]+l_back_max_arr[i+1]
    end
    if max < l_max_arr[i+1]+r_back_max_arr[i]
      max = l_max_arr[i+1]+r_back_max_arr[i]
    end
  end
end
printf("%d\n",max)