import java.util.Scanner
import scala.collection.mutable.{Set => mSet}


object Main {

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

    val maxNum = 100
    val connectible = Array.fill(maxNum)(mSet[Int]())
    val used = Array.fill(maxNum)(false)

    var n = sc.nextInt()
    while (n != 0) {

      for (i <- 0 until n) {
        val a, b = sc.nextInt() - 1
        connectible(a) += b
        connectible(b) += a
      }

      println((for (ring <- 0 until maxNum if connectible(ring).nonEmpty) yield trace(ring)).max)

      n = sc.nextInt()
      connectible.foreach(set => set.clear)
    }

    def trace(lastRing: Int): Int = {
      var ret = 0
      for (nextRing <- connectible(lastRing) if !used(nextRing)) {
        used(nextRing) = true
        ret = math.max(ret, trace(nextRing) + 1)
        used(nextRing) = false
      }
      ret
    }
  }
}