#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int in_num[101];
int tmp_depth;
vector<int> G[101],GROUP[101];

int boss[101],height[101];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}


void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}

void init(){
	for(int i = 1; i <= 100; i++){
		boss[i] = i;
		height[i] = 0;
	}
}

void recursive(bool visited[101],int node_id,int depth,int group_id){
	tmp_depth = max(tmp_depth,depth);

	for(int i = 0; i < G[node_id].size(); i++){
		if(visited[G[node_id][i]])continue;

		bool next_visited[101];
		for(int k = 0; k < GROUP[group_id].size(); k++)next_visited[GROUP[group_id][k]] = visited[GROUP[group_id][k]];	//???????????°?????????????????±?????????????¶??????°??????
		next_visited[G[node_id][i]] = true;
		recursive(next_visited,G[node_id][i],depth+1,group_id);
	}
}


void func(){

	for(int i = 1; i <= 100; i++){
		in_num[i] = 0;
		G[i].clear();
		GROUP[i].clear();
	}

	init();

	int from,to;
	for(int loop = 0; loop < N; loop++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
		G[to].push_back(from);
		in_num[to]++;
		in_num[from]++;
		unite(from,to);
	}

	for(int i = 1; i <= 100; i++){
		if(in_num[i] == 0)continue;
		GROUP[get_boss(i)].push_back(i);
	}

	int max_depth = 1,min_in_num;
	bool visited[101];
	for(int i = 1; i <= 100; i++){
		if(GROUP[i].size() == 0 || GROUP[i].size() < max_depth)continue;

		min_in_num = BIG_NUM;
		for(int k = 0; k < GROUP[i].size(); k++){
			min_in_num = min(min_in_num,in_num[GROUP[i][k]]);
		}

		for(int k = 0; k < GROUP[i].size(); k++){
			if(in_num[GROUP[i][k]] == min_in_num){
				for(int p = 0; p < GROUP[i].size(); p++)visited[GROUP[i][p]] = false;
				visited[GROUP[i][k]] = true;
				tmp_depth = 0;
				recursive(visited,GROUP[i][k],1,i);
				max_depth = max(max_depth,tmp_depth);
			}
		}
	}
	printf("%d\n",max_depth);
}


int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}