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