#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int a[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = 0;
    for (int j = i; j <= n && j != -1; j = a[j]) tmp++;
    ans = max(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}
