#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef vector< int > Array;
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }

int n;
vector< Array > edges;
bool visit[110];

int rec(int v) {
	int res = 1;
	
	visit[v] = 1;
	
	int e_size = size_of(edges[v]);
	for_(i,0,e_size) {
		int u = edges[v][i];
		if (visit[u]) continue;
		maxUpdate(res, rec(u) + 1);
	}
	
	visit[v] = 0;
	
	return res;
}

void solve() {
	minit(visit, 0);
	int ans = 0;
	for_(i,1,101) maxUpdate(ans, rec(i));
	printf("%d\n", ans);
}

int main() {
	while (cin >> n, n) {
		edges.assign(101, Array());
		
		for_(i,0,n) {
			int a, b;
			scanf("%d %d", &a, &b);
			edges[a].push_back(b);
			edges[b].push_back(a);
		}
		
		solve();
	}
	return 0;
}