#include <bits/stdc++.h>
using namespace std;

int N;
vector<int> kids[100000];

int height(int v) {
  int n = kids[v].size();
  vector<int> heights;
  for(int w : kids[v]) heights.push_back(height(w));
  sort(heights.begin(), heights.end());
  int res = 1;
  for(int i = 0; i < n; ++i) {
    res = max(res, n - i + heights[i]);
  }
  return res;
}

int main() {
  cin >> N;
  for(int i = 1; i <= N - 1; ++i) {
    int A; cin >> A; --A; kids[A].push_back(i);
  }
  cout << height(0) - 1 << endl;
  return 0;
}
