#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> nodes[N];
//每个树的最大高度是其子树的最大高度+该树的孩子数量
int dfs(int k){
//int sum = 0;
int sz = nodes[k].size();
int _max = 0;
for(int i = 0; i < sz; i++){
_max = max(_max, dfs(nodes[k][i]));
}
int sum = _max + sz;
//cout<<sum<<endl;
return sum;
}
int main(){
int n, x;
cin>>n;
for(int i = 2; i <= n; i++){
cin>>x;
nodes[x].push_back(i);
}
cout<<dfs(1)<<endl;
return 0;
}