N = gets.to_i

problems = N.times.map { gets.split.map(&:to_i) }

r_min = Float::INFINITY
l_max = 0

problems.each do |l, r|
  l_max = l if l_max < l
  r_min = r if r_min > r
end

def f(list)
  min_r_asc = Array.new(N, Float::INFINITY)
  min_r_desc = Array.new(N, Float::INFINITY)
  max_l_asc = Array.new(N, 0)
  max_l_desc = Array.new(N, 0)

  max_l_asc[0] = list[0][0]
  min_r_asc[0] = list[0][1]
  max_l_desc[N - 1] = list[N - 1][0]
  min_r_desc[N - 1] = list[N - 1][1]

  1.upto(N - 1) do |i|
    max_l_asc[i] = [max_l_asc[i - 1], list[i][0]].max
    min_r_asc[i] = [min_r_asc[i - 1], list[i][1]].min
  end

  (N - 2).downto(0) do |i|
    max_l_desc[i] = [max_l_desc[i + 1], list[i][0]].max
    min_r_desc[i] = [min_r_desc[i + 1], list[i][1]].min
  end

  ans = 0

  0.upto(N - 2) do |i|
    s = min_r_asc[i] - max_l_asc[i] + 1
    t = min_r_desc[i + 1] - max_l_desc[i + 1] + 1

    v = [s, 0].max + [t, 0].max

    ans = v if ans < v
  end

  ans
end

list_a = problems.sort_by { |l, r| -[r_min - l + 1, 0].max }
list_b = problems.sort_by { |l, r| -[r - l_max + 1, 0].max }

puts [f(list_a), f(list_b)].max
