#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[2000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int dep = 1, id = i;
    while (0 <= a[id]) {
      dep++;
      id = a[id] - 1;
    }
    ans = max(ans, dep);
  }
  cout << ans << endl;
}
