import java.util.Scanner
import scala.collection.mutable.{IndexedSeq => iSeq}

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    var n = sc.nextInt()

    while (n != 0) {

      val connectibleAll = iSeq.fill(100)(Set[Int]())

      for (i <- 0 until n) {
        val a, b = sc.nextInt() - 1
        connectibleAll(a) += b
        connectibleAll(b) += a
      }
      val contractedConnectible = connectibleAll.zipWithIndex.filter(_._1.nonEmpty)
      val dict = contractedConnectible.map(_._2).zipWithIndex.toMap
      val connectible = contractedConnectible.map(t => (dict(t._2), t._1.map(dict(_))))
      val used = iSeq.fill(connectible.size)(false)


      def trace(ring: (Int, Set[Int])): Int = {
        val (lastRing, nextRings) = ring
        used(lastRing) = true
        val result = nextRings
          .filterNot(used(_)).map(r => trace(connectible(r)) + 1)
          .foldLeft(1)((z, n) => if (n > z) n else z)
        used(lastRing) = false
        result
      }

      println(connectible.map(trace).max)

      n = sc.nextInt()
    }
    sc.close()
  }
}