#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<vector<int> > edges;
bitset<100> used;

int solve(int pos)
{
    used[pos] = true;

    int ret = 1;
    for(unsigned i=0; i<edges[pos].size(); ++i){
        int next = edges[pos][i];
        if(!used[next])
            ret = max(ret, 1 + solve(next));
    }

    used[pos] = false;
    return ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        edges.assign(100, vector<int>(0));
        for(int i=0; i<n; ++i){
            int a, b;
            cin >> a >> b;
            edges[a-1].push_back(b-1);
            edges[b-1].push_back(a-1);
        }

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