#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int solve(const vector< vector<int> >& g, int p){
	vector<int> r;
	for(const int& t : g[p]){
		r.push_back(solve(g, t));
	}
	sort(r.begin(), r.end());
	int res = 0;
	int n = r.size();
	for(int i=0;i<n;i++){
		res = max(res, r[i]+n-i);
	}
	return res;
}

int main(){
	int N;
	while(cin >> N){
		vector< vector<int> > g(N);
		for(int i=1;i<N;i++){
			int a; cin >> a;
			g[a-1].push_back(i);
		}
		cout << solve(g, 0) << endl;
	}
}
