import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int n;
    const N = 100;
    while (readf("%d\n", &n), n) {
        int[][] g = new int[][N];
        foreach (i; 0 .. n) {
            int a, b; readf("%d %d\n", &a, &b);
            a--; b--;
            g[a] ~= b;
            g[b] ~= a;
        }
        bool[] used = new bool[N];
        int dfs(int c) {
            int ret = 1;
            foreach (next; g[c]) {
                if (used[next]) continue;
                used[next] = true;
                ret = max(ret, dfs(next) + 1);
                used[next] = false;
            }
            return ret;
        }

        int ans = 0;
        foreach (i; 0 .. N) {
            used[i] = true;
            ans = max(ans, dfs(i));
            used[i] = false;
        }
        ans.writeln;
    }
}