#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
int par[110000];
vector<int> ch[110000];
int depth[110000];
void solve(int a){
	vector<int> d;
	for(int i = 0; i < ch[a].size(); i++){
		solve(ch[a][i]);
		d.push_back(depth[ch[a][i]]);
	}
	sort(d.begin(), d.end());
	reverse(d.begin(), d.end());
	depth[a] = 0;
	for(int i = 0; i < d.size(); i++){
		depth[a] = max(d[i]+i,depth[a]);
	}
	depth[a] ++;
}
int main(){
	cin >> n;
	for(int i = 2; i <= n; i++){
		cin >> par[i];
		ch[par[i]].push_back(i);
	}
	par[1] = 0;
	solve(1);
	cout << depth[1] - 1 << endl;
}
