#include <bits/stdc++.h>
using namespace std;
struct Max
{
int m1, m2;
};
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
int parent[n];
int deg[n] = {0};
queue<int> Q;
Max max_2h[n] = {0, 0};
for (int i = 0; i < n; i++) parent[i] = -1;
for (int i = 1; i < n; i++)
{
int p, c;
scanf("%d %d", &p, &c);
parent[c] = p;
deg[p] += 1;
}
for (int i = 0; i < n; i++) if (deg[i] == 0) Q.push(i);
int ans = 0;
while(!Q.empty())
{
int point = Q.front();
Q.pop();
if (parent[point] == -1) continue;
int Parent = parent[point];
max_2h[Parent].m1 = max(max_2h[Parent].m1, max_2h[point].m2+1);
if (max_2h[Parent].m1 > max_2h[Parent].m2) swap(max_2h[Parent].m1, max_2h[Parent].m2);
ans = max(ans, max_2h[Parent].m1+max_2h[Parent].m2);
if ((--deg[Parent]) == 0) Q.push(Parent);
}
printf("%d\n", ans);
}
}