local n = io.read("*n")
local c = 0LL + io.read("*n")
local x, v = {}, {}
for i = 1, n do
  x[i] = 0LL + io.read("*n")
  v[i] = 0LL + io.read("*n")
end

local score_forward = {v[1] - x[1]}
do
  local cur = score_forward[1]
  for i = 2, n do
    cur = cur + v[i] - (x[i] - x[i - 1])
    if score_forward[i - 1] < cur then
      score_forward[i] = cur
    else
      score_forward[i] = score_forward[i - 1]
    end
  end
end

local score_backward = {}
do
  for i = 1, n do score_backward[i] = 0LL end
  score_backward[n] = v[n] - (c - x[n])
  local cur = score_backward[n]
  for i = n - 1, 1, -1 do
    cur = cur + v[i] - (x[i + 1] - x[i])
    if score_backward[i + 1] < cur then
      score_backward[i] = cur
    else
      score_backward[i] = score_backward[i + 1]
    end
  end
end

local ret = 0LL
for i = 1, n do
  local scorecand = score_forward[i]
  if ret < scorecand then
    ret = scorecand
  end
  if i < n then
    scorecand = scorecand - x[i] + score_backward[i + 1]
    if ret < scorecand then
      ret = scorecand
    end
  end
end
for i = n, 1, -1 do
  local scorecand = score_backward[i]
  if ret < scorecand then
    ret = scorecand
  end
  if 1 < i then
    scorecand = scorecand - (c - x[i]) + score_forward[i - 1]
    if ret < scorecand then
      ret = scorecand
    end
  end
end
local str = tostring(ret):gsub("LL", "")
print(str)
