#include <bits/stdc++.h>
int dd[2000], pp[2000];
int solve(int i) {
  return dd[i] > 0 ? dd[i] : (dd[i] = 1 + (pp[i] == -2 ? 0 : solve(pp[i])));
}
int main() {
  int n, i, max;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &pp[i]), pp[i]--;
  max = 0;
  for (i = 0; i < n; i++) {
    solve(i);
    if (max < dd[i]) max = dd[i];
  }
  printf("%d\n", max);
  return 0;
}
