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(Ring.maxNum)(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 newConnectible = contractedConnectible.map(t => (dict(t._2), t._1.map(dict(_))))

      println(new Ring(newConnectible).get)

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

object Ring {
  val maxNum = 100
}

class Ring(connectible: iSeq[(Int, Set[Int])]) {
  val used = iSeq.fill(connectible.size)(false)

  def get = {
    connectible.map(trace).view.max
  }

  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)
      .fold(1)((z, n) => if (n > z) n else z)
    used(lastRing) = false
    result
  }
}