#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

vector<int> to[100];
bool used[100];

void addEdge(int a, int b) {
    to[a].push_back(b);
    to[b].push_back(a);
}

int dfs(int v) {
    int ret = 1;
    used[v] = true;
    for (int i=0; i<(int)to[v].size(); ++i) {
        if ( ! used[to[v][i]]) {
            ret = max(ret, 1 + dfs(to[v][i]));
        }
    }
    used[v] = false;
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        fill(to, to+100, vector<int>());
        int a, b;
        for (int i=0; i<n; ++i) {
            cin >> a >> b;
            --a, --b;
            addEdge(a, b);
        }
        int ret = 0;
        for (int i=0; i<100; ++i) {
            memset(used, false, sizeof used);
            ret = max(ret, dfs(i));
        }
        cout << ret << endl;
    }
    return 0;
}