#include<iostream>
#include<vector>
#include<string.h>
#include<stack>
using namespace std;

struct Node{
  vector<int> edge;
};

typedef vector<Node> Graph;
#define fi first
#define se second
#define pii pair<int,int>

bool visited[110];
int dist[110];
int exist[110];
int ne[110];

int dfs(const Graph &g, int n) {
  int tmp,res=0;
  visited[n] = true;
  exist[n] = 0;

  for(int i=0; i<g[n].edge.size(); ++i) {
    if(visited[g[n].edge[i]]) continue;
    tmp = dfs(g, g[n].edge[i]);
    if(res < tmp) res = tmp;
  }

  visited[n] = 0;
  return res+1;
}

int main() {
  int n,a,b,tmp,br;
  while(cin>>n, n) {
    Graph g(100);
    int mindegree = 100,mind = 0;

    for(int i=0; i<100; ++i) {
      visited[i] = false;
      dist[i] = 0;
      exist[i] = 0;
    }

    for(int i=0; i<n; ++i) {
      cin>>a>>b;
      a--,b--;
      g[a].edge.push_back(b);
      g[b].edge.push_back(a);
      exist[a] = exist[b] = 1;
    }

    int max = 0;
    for(int j=1;;j++) {
      for(int i=0; i<100; ++i) {
	if(g[i].edge.size() == j) {
	  tmp = dfs(g, i);
	  if(max < tmp) max = tmp;
	}
      }

      br = 1;
      for(int i=0; i<100; ++i)
	if(exist[i]) {
	  br = 0;
	  break;
	}
      if(br) break;
    }

    cout<<max<<endl;
  }
}