#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#include<unordered_map>
#include<set>
using namespace std;

vector<int>rinsetu[105];
bool S[105];
int MAX;
void saiki(int a,int b) {
	MAX = max(MAX, b);
	for (int i : rinsetu[a]) {
		if (!S[i]) {
			S[i] = true;
			saiki(i, b + 1);
			S[i] = false;
		}
	}
}
signed main() {
	int a; 
	while (cin >> a,a) {
		MAX = 0;
		for (int i = 0; i < 105; i++)rinsetu[i].clear();
		memset(S, false, sizeof(S));
		for (int b = 0; b < a; b++) {
			int c, d; scanf("%d%d", &c, &d); c--; d--;
			rinsetu[c].push_back(d);
			rinsetu[d].push_back(c);
		}
		for (int b = 0; b < 105; b++) {
			S[b] = true;
			saiki(b, 1);
			S[b] = false;
		}
		cout << MAX << endl;
	}
}