#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,ans,u[100];vector<vector<int> > ad;
void dfs(int c,int m){
	if(ans<m)ans=m;
	rep(i,ad[c].size())if(!u[ad[c][i]]){
		u[ad[c][i]]=1;dfs(ad[c][i],m+1);u[ad[c][i]]=0;
	}
}
int main(){
	while(cin>>n,n){
		ad.clear();ad.resize(100);
		rep(i,n){
			int a,b; cin>>a>>b; a--,b--;
			ad[a].push_back(b),ad[b].push_back(a);
		}
		ans=1;rep(i,100)u[i]=0;
		rep(i,100)if(!ad[i].empty()){
			u[i]=1;dfs(i,1);u[i]=0;
		}
		cout<<ans<<endl;
	}
	return 0;
}