#include <bits/stdc++.h>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define pb push_back

using namespace std;

const int N = 1e5 + 10;

vector<int> G[N];
int n;
int dp[N];

void DFS(int o){
	vector<int> val;
	for(int v : G[o]) DFS(v), val.pb(dp[v] + 1);
	sort(val.begin(), val.end());

	int now = int(G[o].size()) - 1;
	for(int v : val) dp[o] = max(dp[o], v + now), --now;
}

int main(){
	scanf("%d", &n);
	For(i, 2, n){
		int x;
		scanf("%d", &x);
		G[x].pb(i);
	}

	DFS(1);
	printf("%d\n", dp[1]);
	return 0;
}