def solve(edge)
  answer = 0
  edge.each do |key, value|
    answer = [answer, bfs(edge, key)].max
  end
  answer
end

def bfs(edge, vertex)
  result = 0
  visited = Hash.new
  q = Array.new.unshift([vertex, [vertex]])
  until q.empty? do
    u, used = q.shift
    next if visited[used]
    visited[used] = true
    result = [result, used.size].max
    edge[u].each do |v|
      next if used.include?(v)
      q.unshift([v, (used+[v]).sort])
    end
  end
  result
end

until (n=gets.to_i)==0 do
  edge = Hash.new {|h,k|h[k]=Array.new}
  n.times do
    i, j = gets.split.map{|e|e.to_i-1}
    edge[i].push(j)
    edge[j].push(i)
  end
  p solve(edge)
end