import java.util.*;
import java.io.*;
public class d5 {
	static PrintWriter fOut;
	static int max = 0;
	public static void main(String[] args) throws IOException {
		Scanner fIn = new Scanner(new File("DATA5.txt"));
		fOut = new PrintWriter(new FileWriter("OUT5.txt"));
		
		for(int i = 0 ; i < 5 ; i ++) {
			max = 0;
			int n = fIn.nextInt();
			int[][] arr = new int[n][2];
			//Node[] nodes = new Node[n];
			for(int j = 0 ; j < n ; j ++) {
				arr[j][0] = fIn.nextInt();
				arr[j][1] = fIn.nextInt();
				//nodes[j] = new Node(arr[j][0],arr[j][1]);
			}
			/*for(int j = 0 ; j < n ; j ++) {
				for(int k = 0 ; k < n ; k ++) {
					if(nodes[j].next == nodes[k].now) {
						
					}
				}
			}*/
			for(int j = 0 ; j < n ; j ++) {
				int c = arr[j][0];
				rec(c,0,arr,c);
				int d = arr[j][1];
				rec(d,0,arr,d);
			}
			fOut.println(max);
		}
		fOut.close();
	}
	static void rec(int cur, int count, int[][] ns, int start) {
		if(cur == -1) return;
		
		/*if(ns.length == 0) {
			System.out.println("b");
			return;
		}*/
		if(count != 0 && cur == start) {
			if(count > max) {
				System.out.println("-------"+count);
				max = count;
			}
			//System.out.println("c");
			return;
		}
		
		for(int i = 0 ; i < ns.length ; i ++) {
			//System.out.println("now" + cur + " ns:" + ns[i][0] + " " + ns[i][1] + " count:" + count);
			int[][] newns = new int[ns.length][2];
			copyEx(ns,newns,i);
			if(ns[i][0] == cur) {
				
				rec(ns[i][1] , count + 1 , newns , start);
			}
			if(ns[i][1] == cur) {
				rec(ns[i][0] , count + 1 , newns , start);
			}
		}
	}
	static void copyEx(int[][] a , int[][] b, int kinshi) {
		//b = new int[a.length][2];
		for(int i = 0 ; i < a.length ; i ++) {
			if(i == kinshi) {
				b[i][0] = -1;
				b[i][1] = -1;
			}
			else {
				b[i][0] = a[i][0];
				b[i][1] = a[i][1];
			}
		}
	}
}
