### main

loop do
  n = gets.strip.to_i
  break if n == 0

  rn = 0
  rids = {}
  redges = []

  n.times do
    a, b = gets.strip.split(' ').map{|s| s.to_i}
    if rids[a].nil?
      rids[a] = rn
      rn += 1
    end
    if rids[b].nil?
      rids[b] = rn
      rn += 1
    end
    redges << [rids[a], rids[b]]
  end
  #p rn
  #p redges

  edges = rn.times.map{[]}
  nbrs = rn.times.map{[]}

  for re in redges
    a, b = re
    edges[a][b] = edges[b][a] = 1
    nbrs[a] << b
    nbrs[b] << a
  end
  #p edges
  #p nbrs

  max_cl = 0

  for st in (0...rn)
    dists = rn.times.map{{}}
    dists[st][1 << st] = 1

    q = [[st, 1 << st]]

    while ! q.empty?
      r0, bits0 = q.shift

      for r1 in nbrs[r0]
        b1 = 1 << r1
        if (bits0 & b1) == 0
          bits1 = bits0 | b1
          d1 = dists[r1][bits1] = dists[r0][bits0] + 1
          q << [r1, bits1]
          max_cl = d1 if max_cl < d1
        end
      end
    end
  end

  puts max_cl
end