N = gets.to_i
LRs = readlines.map{|l| l.split.map(&:to_i)}

ls, rs, ll, rr, ss = [], [], 0, 10**9 + 1, 0
LRs.each do |l, r|
  r += 1
  s = r - l
  ls << l; rs << r
  ll = l if l > ll
  rr = r if r < rr
  ss = s if s > ss
end
nz = ->(a, b){a >= b ? a - b : 0}
ans1 = nz[rr, ll] + ss
as = (0 ... N).map{|i| nz[rs[i], ll]}
bs = (0 ... N).map{|i| nz[rr, ls[i]]}
cs = (0 ... N).sort_by{|i| as[i] || -bs[i]}
ans2 = (1 .. N - 1).map{|k| cs.take(k).map{|i| bs[i]}.min + cs.drop(k).map{|i| as[i]}.min}.max
puts [ans1, ans2].max