#include <bits/stdc++.h>
int g[2010];
int main() {
  int t, i;
  FILE *input = stdin;
  FILE *output = stdout;
  fscanf(input, "%d", &t);
  const int n = t;
  for (i = 1; i != n + 1; i++) fscanf(input, "%d", &g[i]);
  int count = 0, cur;
  for (i = 1; i != n + 1; i++) {
    cur = i;
    t = 1;
    while (g[cur] != -1) {
      t++;
      cur = g[cur];
    }
    if (t > count) count = t;
  }
  fprintf(output, "%d\n", count);
  return 0;
}
