#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 1e5;
vector <int> G[N + 7];
int dp[N + 7];

void dfs(int v) {
	vector <int> T;
	for(auto u : G[v]) {
		dfs(u);
		T.push_back(dp[u]);		
	}
	sort(T.begin(), T.end(), greater <int>());
	for(int i = 0; i < (int) T.size(); ++i) dp[v] = max(dp[v], 1 + T[i] + i);
}

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for(int i = 2; i <= n; ++i) {
		int x;
		cin >> x;
		G[x].push_back(i);
	}
	dfs(1);
	cout << dp[1] << endl;
	return 0;
}