#include <bits/stdc++.h>
using namespace std;
vector<int> children[2005];
int depth(int v) {
  int highest_child = 0;
  for (int i = 0; i < (int)children[v].size(); i++) {
    int child = children[v][i];
    highest_child = max(highest_child, depth(child));
  }
  return highest_child + 1;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d", &p);
    if (p == -1)
      children[0].push_back(i);
    else
      children[p].push_back(i);
  }
  printf("%d\n", depth(0) - 1);
  return 0;
}
