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

vector<int> a[100001];
int d[100001];

int N;

int func(int index)
{
	if (a[index].size() == 0)
	{
		return 0;
	}
	else
	{
		vector <int> b;
		int mx = 0, t = 0;
		for (int i : a[index])
		{
			b.push_back(func(i));
		}
		sort(b.begin(), b.end());
		for (int i = b.size() - 1; i >= 0; i--)
		{
			b[i] += t++;
			mx = max(mx, b[i]);
		}
		return mx + 1;
	}
}

int main()
{
	int g;
	cin >> N;
	for (int i = 2; i <= N; i++)
	{
		cin >> g;
		a[g].push_back(i);
	}
	cout << func(1);
}