def link(link,c)
  cand = c[link[-1]][1] - link

  if cand.empty?
    size = link.size
  else
    size = 0
    for i in 0..cand.size-1
      size = [link(link+[cand[i]],c),size].max
    end
  end
  
  size
end

while true
  n = gets.to_i
  break if n == 0

  str = Array.new(n){gets.split(" ").map{|s| s.to_i}}
  c = []
  for i in 0..n-1
    ri = str[i]
    c[ri[0]].nil? ? c[ri[0]] = [ri[1]] : c[ri[0]] << ri[1]
    c[ri[1]].nil? ? c[ri[1]] = [ri[0]] : c[ri[1]] << ri[0]
  end

  c = c.map.with_index{|arr,id| arr = [id,arr.uniq.sort] unless arr.nil?}

  l = 0
  for t in 0..c.size-1
    l = [link([c[t][0]],c),l].max unless c[t].nil?  
  end

  puts l
end