io = STDIN
n=io.gets.to_i
ar=n.times.map do
  io.gets.split.map(&:to_i)
end.sort_by{|l,r|l}
def calc(arg)
  lmax=arg[-1][0]
  rmin=arg.min_by{|l,r|r}[1]
  rmin-(lmax-1)
end
ans=0
(n-1).times do |i|
  ar1=ar[0..i]
  ar2=ar[i+1..-1]
  ans=[ans,calc(ar1)+calc(ar2)].max
end
p ans
