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

vector<vector<int>>M;

int solve(int k) {
	vector<int>num;
	num.push_back(0);
	for (int i = 0; i < M[k].size(); i++) {
		num.push_back(solve(M[k][i]));
	}
	sort(num.begin(), num.end(),greater<int>());
	int Mx = 0;
	for (int i = 0; i < M[k].size(); i++) {
		num[i] += i + 1;
		Mx = max(Mx, num[i]);
	}
	return Mx;
}

int main()
{
	int n; cin >> n;
	M.resize(n + 1);
	for (int i = 1; i < n; i++) {
		int a; cin >> a;
		M[a].push_back(i+1);
	}

	cout << solve(1) << endl;

    return 0;
}
