#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=100005;

vector<int>e[N],d[N];
int n;

int dfs(int x){
	for(int v:e[x])d[x].push_back(dfs(v));
	sort(d[x].begin(),d[x].end());
	int a=0,c=d[x].size();
	for(int v:d[x])a=max(a,v+c--);
	return a;
}

int main(){
	scanf("%d",&n);
	for(int i=2,u;i<=n;i++)scanf("%d",&u),e[u].pb(i);
	printf("%d\n",dfs(1));
	return 0;
}