#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<vector<int> > G;
vector<bool> used;
int rec(int pos)
{
    used[pos] = true; int ret = 1;
    
    for(int i = 0; i < G[pos].size(); i++)
    {
        if(!used[G[pos][i]])
        {
            ret = max(ret, rec(G[pos][i]) + 1);
        }
    }
    
    used[pos] = false;
    
    return ret;
}
int main()
{
    int N, A, B;
    
    while(true)
    {
        scanf("%d", &N);
        
        if(N == 0) { break; }
        G = vector<vector<int> >(100, vector<int>());
        
        used = vector<bool>(100);
    
        for(int i = 0; i < N; i++)
        {
            scanf("%d", &A); A--;
            scanf("%d", &B); B--;
        
            G[A].push_back(B);
            G[B].push_back(A);
        }
        
        int nodes = 0;
        
        for(int i = 0; i < 100; i++)
        {
            if(G[i].size())
            {
                nodes++;
            }
        }
    
        int ret = 0;
    
        for(int i = 0; i < 100; i++)
        {
            if(G[i].size())
            {
                ret = max(ret, rec(i));
                
                if(ret == nodes) { break; }
            }
        }
        
        printf("%d\n", ret);
    }
    
    return 0;
}