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