#include <bits/stdc++.h>

using namespace std;

int N;
int ma;
vector<int> G[105];
bool visit[105];

void dfs(int cur, int depth = 1)
{
    ma = max(ma, depth);

    for (int u : G[cur]) {
        if (visit[u]) {
            continue;
        }

        visit[u] = true;

        dfs(u, depth + 1);

        visit[u] = false;
    }
}

int main()
{
    while (cin >> N, N) {
        for (int i = 0; i < 100; ++i) G[i].clear();

        for (int i = 0; i < N; ++i) {
            int a, b; cin >> a >> b;
            --a, --b;
            G[a].push_back(b);
            G[b].push_back(a);
        }

        ma = 0;

        for (int i = 0; i < 100; ++i) {
            visit[i] = true;
            dfs(i);
            visit[i] = false;
        }

        cout << ma << endl;
    }
}