
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#define rep(i,n) for(int (i)=0;(i) < (n);(i)++)
#define MAX 110
using namespace std;
vector<int> G[MAX];
bool flag[MAX];

int dfs(int now){
    flag[now]=1;
    int ret = 1;
    rep(i,G[now].size()){
        if(flag[G[now][i]]==0)
            ret = max(ret,dfs(G[now][i])+1);
    }
    flag[now]=0;
    return ret;
}

int main() {
    int n;
    while(scanf("%d",&n),n!=0){
        rep(i,MAX){
            G[i].clear();
            flag[i]=0;
        }
        int x,y;
        rep(i,n){
            scanf("%d %d",&x,&y);
            x--;
            y--;
            G[x].push_back(y);
            G[y].push_back(x);
        }
        rep(i,MAX){
            if(G[i].empty())
                break;
            sort(G[i].begin(),G[i].end());
            G[i].erase(unique(G[i].begin(),G[i].end()),G[i].end());
        }
        int ret = 0;
        rep(i,MAX){
            ret = max(ret,dfs(i));
        }
        printf("%d\n",ret);
    }
    return 0;
}