class Graph
  Infinity = 1000000000
  attr_accessor :size, :cost
  def initialize(size, adjacentMatrix=Array.new(n){Array.new(n)})
    @size = size
    @cost = adjacentMatrix.map(&:dup)
  end
  def Dijkstra2(from)
    distance = Array.new(@size, -Infinity)
    distance[from] = 0
    unused = (0...@size).to_a
    until unused.empty? do
      current = unused.sort!{|a,b| distance[a]<=>distance[b]}.pop
      break if distance[current] == -Infinity
      unused.each do |v|
        next unless @cost[current][v]
        distance[v] = [distance[v], distance[current]+@cost[current][v]].max
      end
    end
    distance.max
  end
end

Max = 1000000000
until (n=gets.to_i)==0 do
  adj = Array.new(100) {Array.new(100)}
  n.times do
    i, j = gets.split.map(&:to_i)
    i -= 1
    j -= 1
    adj[i][j] = adj[j][i] = 1
  end
  answer = 0
  g = Graph.new(100,adj)
  100.times do |i|
    answer = [answer, g.Dijkstra2(i)+1].max
  end
  p answer
end