N = gets.to_i

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

def f(problems)
  min_asc = Array.new(N, -Float::INFINITY)
  min_dsc = Array.new(N, -Float::INFINITY)

  min_la = 0
  min_lb = 0

  N.times do |i|
    la = problems[i][0]
    lb = problems[N - i - 1][0]

    min_la = la if min_la < la
    min_lb = lb if min_lb < lb

    min_asc[i] = min_la
    min_dsc[N - i - 1] = min_lb
  end

  ans = 0

  (N - 1).times do |i|
    va = problems[0][1] - min_asc[i] + 1
    vb = problems[i + 1][1] - min_dsc[i + 1] + 1

    v = [va, 0].max + [vb, 0].max

    if ans < v
      ans = v
    end
  end

  ans
end

r_sorted = problems.sort_by { |l, r| r }
l_sorted = problems.sort_by { |l, r| l }

v1 = f(r_sorted)
v2 = f(l_sorted)

puts [v1, v2].min
