#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e7+5;
vector<LL>tree[N];
LL Max=-1;
void dfs(LL u,LL f,LL dep){
Max=max(Max,dep);
for(LL v:tree[u]){
if(v==f||v==u||u==f)continue;
dfs(v,u,dep+1);
}
}
int main(){
LL n;
cin>>n;
for(LL i=1;i<=n;i++){
LL v1,v2;
cin>>v1>>v2;
tree[i].push_back(v1);
tree[i].push_back(v2);
}
dfs(1,0,0);
cout<<Max;
return 0;
}