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,eq)
  min1=ar[0][1]
  (N-eq).times do |i|
    ar[i]<<[min1,ar[i][1]].min
  end
  min2=ar[-1][1]
  (N-eq).times do |i|
    ar[-1-i]<<[min2,ar[-1-i][1]].min
  end
end
eq=0
ar.each do |l,r|
  eq+=1 if l==r
end

def calc(ar,i)
  l1=ar[i][0]
  r1=ar[i][2]
  l2=ar[-1][0]
  r2=ar[i+1][3]
  #p [l1,r1,l2,r2,r1-l1+r2-l2+2]
  r1-l1+r2-l2+2
end
ans=0
if eq ==0
  add(ar,0)
  (N-1).times do |i|
    ans=[ans,calc(ar,i)].max
  end
elsif eq==1
  ar.reject!{|l,r|l==r}
  add(ar,eq)
  (N-1-eq).times do |i|
    ans=[ans,calc(ar,i)].max
  end
  ans+=1
else
  ans=2
end
p ans
