def dfs(i, yet, hop)
  $r[i].each do |t|
    if yet[i][t]
      yet[i][t] = yet[t][i] = false
      if hop[t] != -1
        $ret = hop[i] + 1 if $ret < hop[i] + 1
      else
        hop[t] = hop[i] + 1
        dfs(t, yet, hop)
      end
    end
  end
end
while n = gets.to_i
  break if n == 0
  g = 101.times.map{ [false] * 101 }
  $r = 101.times.map{ [] }
  m = 0
  n.times do
    a, b = gets.split.map(&:to_i)
    g[a][b] = g[b][a] = true
    $r[a] << b
    $r[b] << a
    m = [a, b, m].max
  end
  ans = 0
  (1..m).each do |i|
    yet = g.map{ |a| a.dup }
    hop = [-1] * (m + 1)
    hop[i] = 0
    $ret = 0
    dfs(i, yet, hop)
    ans = $ret if ans < $ret
  end
  p ans
end