#include <bits/stdc++.h>
using namespace std;
int depth[2005];
int superior[2005];
int main() {
  int a;
  cin >> a;
  map<int, int> depthz;
  int ans = 0;
  for (int g = 0; g < a; g++) {
    int l;
    cin >> l;
    if (l == -1) {
      depth[g] = 1;
    }
    superior[g] = l;
  }
  int numchanges = 1;
  while (numchanges != 0) {
    numchanges = 0;
    for (int g = 0; g < a; g++) {
      if (depth[g] == 0) {
        if (depth[superior[g] - 1] != 0) {
          depth[g] = depth[superior[g] - 1] + 1;
          numchanges += 1;
        }
      }
    }
  }
  for (int g = 0; g < a; g++) {
    if (depthz[depth[g]] == 0) {
      depthz[depth[g]]++;
      ans++;
    }
  }
  cout << ans;
  return 0;
}
