#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int cnt[N], a[N], h[N];
struct cmp {
	bool operator () (int i, int j) {
		return h[i] > h[j];
	}
};
int main() {
	priority_queue<int, vector<int>, cmp> q;
	int n;
	scanf("%d", &n);
	for (int i = 2; i <= n; ++ i) {
		scanf("%d", &a[i]);
		cnt[a[i]] ++;
	}
	for (int i = 1; i <= n; ++ i) if (cnt[i] == 0) q.push(i);
	while(!q.empty()) {
		int p = q.top(); q.pop();
		h[a[p]] = max(h[p], h[a[p]]) + 1;
		cnt[a[p]] --;
		if (cnt[a[p]] == 0) q.push(a[p]);
	}
	printf("%d\n", h[1]);
}

