#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int p[n + 1], x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    p[i] = x;
  }
  int d = 0;
  for (int i = 1; i <= n; i++) {
    int c = 1;
    x = i;
    while (p[x] != -1) {
      c++;
      x = p[x];
    }
    d = max(d, c);
  }
  cout << d << endl;
}
