#include <cstdio>
#include <vector>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;

vector<int> e[100];
bool used[100];
int ans;

void dfs(int x, int y){
	if(used[x]){
		if(y > ans) ans = y;
		return;
	}
	used[x] = true;
	rep(i,e[x].size()){
		//if(used[e[x][i]]) continue;
		dfs(e[x][i],y+1);
	}
	used[x] = false;
}

int main(){
	int n;
	while(scanf("%d", &n),n){
		rep(i,100) e[i].clear();
		rep(i,n){
			int a, b;
			scanf("%d%d", &a, &b);
			a--; b--;
			e[a].pb(b);
			e[b].pb(a);
		}
		ans = 0;
		rep(i,100){
			rep(j,100) used[j] = false;
			dfs(i,0);
		}
		printf("%d\n", ans);
	}
}