#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<vector<int> > edge;
bool visited[128];
int n;
int depth = 0;

int solve(int k) {
	if(visited[k])
		return -1;
	visited[k] = true;
	int res = 0;
	for(int i = 0; i < edge[k].size(); i++) {
		res = max(res, solve(edge[k][i]) + 1);
	}
	visited[k] = false;
	return res;
}

int main() {
	while(cin >> n, n) {
		for(int i = 0; i < 128; i++)
			visited[i] = false;
		edge.clear();
		edge.resize(100);
		for(int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			a--; b--;
			edge[a].push_back(b);
			edge[b].push_back(a);
		}

		int res = 0;
		for(int i = 0; i < 100; i++) {
			res = max(res, solve(i) + 1);
		}
		cout << res << endl;
	}
}