#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,fa[N],dep[N];
vector<int> son[N];
bool cmp(int x,int y){return dep[x]>dep[y];}
void dfs(int x){
	dep[x]=son[x].size();
	for (int i=0;i<son[x].size();i++) dfs(son[x][i]);
	sort(son[x].begin(),son[x].end(),cmp);
	for (int i=0;i<son[x].size();i++) dep[x]=max(dep[x],dep[son[x][i]]+i+1);
}
int main()
{
	scanf("%d",&n);
	for (int i=2;i<=n;i++) scanf("%d",&fa[i]),son[fa[i]].push_back(i);
	dfs(1);
	printf("%d\n",dep[1]);
	return 0;
}