#include<bits/stdc++.h>
using namespace std;
vector <int> des[500010];
int fa[500010];
int dfs(int s)
{
	if (des[s].size()==0) return 0;
	vector <int> vec;int ans=0;
	for (int k=0;k<des[s].size();k++) vec.push_back(dfs(des[s][k]));
	sort(vec.begin(),vec.end());
	for (int i=0;i<vec.size();i++) ans=max(ans,vec[i]+(int)vec.size()-i);
	return ans;
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=2;i<=n;i++)
	{
		scanf("%d",&fa[i]);
		des[fa[i]].push_back(i);
	}//cout<<dfs(2)<<endl;
	printf("%d\n",dfs(1));
}