#include <bits/stdc++.h>
using namespace std;
int n, p[2010], ans, v[2010][2];
void bfs() {
  ans = 0;
  int head = 0, tail = 0;
  for (int i = 1; i <= n; i++)
    if (p[i] == -1) {
      tail++;
      v[tail][0] = i;
      v[tail][1] = 1;
    }
  while (head < tail) {
    head++;
    int x = v[head][0];
    if (ans < v[head][1]) ans = v[head][1];
    for (int i = 1; i <= n; i++)
      if (p[i] == x) {
        tail++;
        v[tail][0] = i;
        v[tail][1] = v[head][1] + 1;
      }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  bfs();
  printf("%d\n", ans);
  return 0;
}
