#include <bits/stdc++.h>

using namespace std;

vector<int> g[100010];

int solve(int cur) {
	vector<int> tmp;
	for (int nex : g[cur]) {
		tmp.push_back(solve(nex));
	}
	int res = 0;
	sort(tmp.rbegin(), tmp.rend());
	for (int i = 0; i < tmp.size(); i++) {
		res = max(res, tmp[i] + i + 1);
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a;
		cin >> a;
		a--;
		g[a].push_back(i);
	}
	cout << solve(0) << endl;
	return 0;
}