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

while true
  n = gets.to_i
  break if n == 0  
  c = Array.new(101){[]}
  for i in 0..n-1
    str = gets.split(" ").map{|s| s.to_i}
    c[str[0]] << str[1]
    c[str[1]] << str[0]
  end
  c.map!{|arr| arr.uniq}
  puts c.inspect
  puts"running..."

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

  puts l.max