#include <bits/stdc++.h>
int main() {
  int i, j, k, m, n, a[2000];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", a + i);
  m = 0;
  for (i = 0; i < n; i++) {
    k = 0;
    j = i;
    while (a[j] != -1) ++k, j = a[j] - 1;
    if (m < k) m = k;
  }
  printf("%d\n", m + 1);
  return 0;
}
