#include <bits/stdc++.h>
using namespace std;
int number[2010];
int main() {
  int i;
  int j;
  int num;
  int ans = 1;
  int n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &number[i]);
  for (i = 1; i <= n; i++) {
    num = 1;
    j = i;
    while (number[j] != -1) {
      num++;
      j = number[j];
    }
    if (ans < num) ans = num;
  }
  printf("%d\n", ans);
  return 0;
}
