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 add(ar)
  min1=ar[0][1]
  N.times do |i|
    ar[i]<<[min1,ar[i][1]].min
  end
  min2=ar[-1][1]
  N.times do |i|
    ar[-1-i]<<[min2,ar[-1-i][1]].min
  end
end
add(ar)
def calc(ar,i)
  l1=ar[i][0]
  r1=ar[i][2]
  l2=ar[-1][0]
  r2=ar[i+1][3]
  r1-l1+r2-l2+2
end
ans=0
(N-1).times do |i|
  ans=[ans,calc(ar,i)].max
end
p ans
