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

r_half_max = 0
r_half_max_count = 0
r_max = 0
r_max_count = 0

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]
    r_max_count = i+1
    if x[i] <= c/2
      r_half_max = r_sum - x[i]
      r_half_max_count = i+1
    end
  end
end

l_half_back_max = 0
if r_half_max_count != 0
  l_half_back_sum = 0
  (n-r_half_max_count).times do |i|
    l_half_back_sum += v[(n-1)-i]
    if l_half_back_max < l_half_back_sum - 2*(c-x[(n-1)-i])
      l_half_back_max = l_half_back_sum - 2*(c-x[(n-1)-i])
    end
  end
end

l_back_max = 0
if r_max_count != 0
  l_back_sum = 0
  (n-r_max_count).times do |i|
    l_back_sum += v[(n-1)-i]
    if l_back_max < l_back_sum - 2*(c-x[(n-1)-i])
      l_back_max = l_back_sum - 2*(c-x[(n-1)-i])
    end
  end
end


l_half_max = 0
l_half_max_count = 0
l_max = 0
l_max_count = 0

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])
    l_max_count = i+1
    if x[(n-1)-i] >= c/2
      l_half_max = l_sum - (c-x[(n-1)-i])
      l_half_max_count = i+1
    end
  end
end

r_half_back_max = 0
if l_half_max_count != 0
  r_half_back_sum = 0
  (n-l_half_max_count).times do |i|
    r_half_back_sum += v[i]
    if r_half_back_max < r_half_back_sum - 2*x[i]
      r_half_back_max = r_half_back_sum - 2*x[i]
    end
  end
end

r_back_max = 0
if l_max_count != 0
  r_back_sum = 0
  (n-l_max_count).times do |i|
    r_back_sum += v[i]
    if r_back_max < r_back_sum - 2*x[i]
      r_back_max = r_back_sum - 2*x[i]
    end
  end
end

if r_max == 0 && l_max == 0
  printf("%d\n",0)
else
  printf("%d\n",[r_max+l_back_max, l_max+r_back_max,r_half_max+l_half_back_max, l_half_max+r_half_back_max].max)
end