#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<functional>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<climits>
using namespace std;

int ans;

void Dfs(vector<int> way[100],bool used[100],int n,int d){
	//printf("%d,%d\n",n,d);
	if(used[n]) return;
	used[n] = true;
	ans = max(ans,d);
	for(int i=0;i<way[n].size();i++){
		Dfs(way,used,way[n][i],d+1);
	}
	used[n] = false;
}

int main(){
	int N,A,B;
	while(cin>>N,N){
		ans = 0;
		vector<int> way[100];
		for(int i=0;i<N;i++){
			cin>>A>>B; A--; B--;
			way[A].push_back(B);
			way[B].push_back(A);
		}
		bool used[100]={};
		for(int i=0;i<100;i++){
			Dfs(way,used,i,1);
		}
		printf("%d\n",ans);
	}
	return 0;
}