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