#include <iostream>
#include <set>
#include <cstring>
using namespace std;

int node[101][101];
int visit[101];
int ans,last;
int die[101];
int flag;

void dfs(int now, int cnt, int *st){
	if( cnt>ans ){
		ans=cnt;
		last = now;
		flag = 1;
	}
	for(int next=0; next<101; next++)if( node[now][next] && !visit[next] ){
		visit[next] = die[next] = 1;
		st[cnt] = next;
		dfs(next,cnt+1,st);
		visit[next] = 0;
	}
	return ;
}

int main(){
	int n;
	while(cin>>n,n){
		set<int> s;
		ans = 0;
		memset(node,0,sizeof(node));
		memset(visit,0,sizeof(visit));
		memset(die,0,sizeof(die));
		for(int i=0; i<n; i++){
			int a,b; cin>>a>>b;
			node[a][b] = node[b][a] = 1;
			s.insert(a);
			s.insert(b);
		}
		int tmp[101];
		for(set<int>::iterator it=s.begin(); it!=s.end(); it++)if( !die[*it] ){
			flag = 0;
			
			visit[*it]=1;
			tmp[0] = *it;
			dfs(*it,1,tmp);
			visit[*it]=0;
			
			die[last] = 0;
			//printf("*it:%d\n",*it);

		}
		printf("%d\n",ans);
	}
	return 0;
}