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