#include<bits/stdc++.h>
#define maxn 100100
using namespace std;
vector<int>v[maxn];
int n,dp[maxn];
int comp(int a,int b){return dp[a]>dp[b];}
void dfs(int u){
	for(int i=0;i<v[u].size();++i)dfs(v[u][i]);
	sort(v[u].begin(),v[u].end(),comp);
	for(int i=0,tp=0;i<v[u].size();++i)
		dp[u]=max(dp[u],dp[v[u][i]]+(++tp));
}
int main(){
	scanf("%d",&n);
	for(int i=2,f;i<=n;++i)
		scanf("%d",&f),v[f].push_back(i);
	dfs(1),printf("%d",dp[1]);
}