N = gets.to_i
ls, rs, ll, rr, ss = [], [], 0, 10**9 + 1, 0
readlines.map{|l| l.split.map(&:to_i)}.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}
ans = nz[rr, ll] + ss
ts = (0 ... N).map{|i| [nz[rs[i], ll], nz[rr, ls[i]]]}.sort_by{|a, b| a || -b}
_, bb = ts.shift
ts.each do |a, b|
  ans = a + bb if a + bb > ans
  bb = b if b < bb
end
puts ans