import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int n = in.nextInt();
			int[] p = new int[n];
			int[] l = new int[n];
			int[] r = new int[n];
			int root=0;
			for(int i=0;i<n;i++){
				p[i]=-1;
				l[i]=-1;
				r[i]=-1;
			}
			for(int i=0;i<n-1;i++){
				int tmpp = in.nextInt();
				int tmpc = in.nextInt();
				p[tmpc]=tmpp;
				if(l[tmpp]==-1)l[tmpp]=tmpc;
				else r[tmpp]=tmpc;
			}
			for(int i=0;i<n;i++){
				if(p[i]==-1){
					root=i;
					break;
				}
			}
			System.out.println(result(root,l,r));
		}
		in.close();
	}
	
	private static int result(int start, int[] l, int[] r){
		if(l[start]==-1&&r[start]==-1)return 1;
		if(l[start]==-1&&r[start]!=-1)return 1+result(r[start],l,r);
		if(r[start]==-1&&l[start]!=-1)return 1+result(l[start],l,r);
		else return Math.max(1+result(r[start],l,r), 1+result(l[start],l,r));
	}
}