#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
using namespace std;
typedef struct node{
int f;//
int data;//数据
int cen;//用来储存节点处于第几层
} node;
typedef struct temp
{
int x1;
int y2;
}temp;//临时储存每个节点
int ce(int i,node t[])//求每个节点位于第几层
{
int cen=1,f=t[i].f;
for(int j=i-1;j>0;j--)
{
if(f==t[j].data)
{
cen++;
f=t[j].f;
}
}
return cen+1;
}
int main() //主函数
{
int n,i,maxx=0,k=0;
cin>>n;
node t[55];
//初始化根1
t[0].cen=1;
t[0].data=1;
t[0].f=0;
temp l[n];temp tt;
for(i=1;i<n;i++)
{
cin>>l[i].x1>>l[i].y2;
}
for(i=1;i<n;i++)//冒泡法将每个节点以x从小到大排序
{
for(int j=i;j<n-1;j++)
{
if (l[j].x1>l[j+1].x1)
{
tt=l[j];
l[j]=l[j+1];
l[j+1]=tt;
}
}
}
for(i=1;i<n;i++)//将以x从小到大排序的节点储存在t[]数组
{
t[i].data=l[i].y2;
t[i].f=l[i].x1;
t[i].cen=ce(i,t);
}
for(i=1;i<=t[n-1].cen;i++)//从第一层到最后一层遍历
{
for(int j=0;j<n;j++)
{
if(t[j].cen==i) k++;
}
if(maxx<k) maxx=k;
k=0;
}
cout<<maxx;
}