import java.util.Scanner;
/*
* 题目描述
现在有一棵合法的二叉树,树的节点都是用数字表示,现在给定这棵树上所有的父子关系,求这棵树的高度
输入描述:
输入的第一行表示节点的个数n(1 ≤ n ≤ 1000,节点的编号为0到n-1)组成,
下面是n-1行,每行有两个整数,第一个数表示父节点的编号,第二个数表示子节点的编号
输出描述:
输出树的高度,为一个整数
示例1
输入
5
0 1
0 2
1 3
1 4
输出
3
*/
public class Main {
public static void main(String[] args) {
// System.out.println("");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] help = new int[n];
int[] sons = new int[n];
for(int i = 0; i < n; i++){
help[i] = 0;
}
help[0] = 1;
int max = 1;
for(int i = 1; i < n; i++){
int father = sc.nextInt();
int son = sc.nextInt();
sons[father] += 1;
if(sons[father] <= 2){
help[son] = help[father] + 1;
}
max = Math.max(max, help[son]);
}
// for (int i : help) {
// System.out.print(i + " ");
// }
System.out.println(max);
sc.close();
}
}