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