#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> parent(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> parent[i];
  }
  int level = 1, max_level = 1;
  for (int i = 1; i <= n; i++) {
    level = 1;
    int j = i;
    while (parent[j] != -1) {
      j = parent[j];
      level++;
    }
    if (max_level < level) max_level = level;
  }
  cout << max_level << endl;
}
