local mma, mmi = math.max, math.min
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = {io.read("*n", "*n")}
  t[i][3] = i
end
local lmaxp, rminp = 1, 1
for i = 2, n do
  if t[lmaxp][1] < t[i][1] then
    lmaxp = i
  end
  if t[i][2] < t[rminp][2] then
    rminp = i
  end
end
local cand = mma(0, t[rminp][2] - t[lmaxp][1] + 1)
do
  local maxlen = 0
  for i = 1, n do
    if i ~= lmaxp and i ~= rminp then
      maxlen = mma(maxlen, t[i][2] - t[i][1] + 1)
    end
  end
  cand = cand + maxlen
end
if lmaxp ~= rminp then
  local l_r, r_l = t[rminp][2], t[lmaxp][1]

  local l_l, r_r = false, t[lmaxp][2]
  table.sort(t, function(a, b) return a[1] > b[1] end)
  for i = 1, n do
    if t[i][3] ~= lmaxp then
      l_l = t[i][1]
      cand = mma(cand, mma(0, l_r - l_l + 1) + mma(0, r_r - r_l + 1))
    end
    if t[i][3] ~= rminp then
      r_r = mmi(r_r, t[i][2])
    end
  end
  cand = mma(cand, mma(0, l_r - l_l + 1) + mma(0, r_r - r_l + 1))
end
print(cand)
