#include <bits/stdc++.h>
using namespace std;
int boss[100100], n, m, workers[100100], was[100100];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &boss[i]);
    boss[i]--;
  }
  int cnt = 0;
  while (cnt < n) {
    m++;
    for (int i = 0; i < n; i++) workers[i] = 0;
    for (int i = 0; i < n; i++)
      if (boss[i] >= 0) workers[boss[i]]++;
    for (int i = 0; i < n; i++)
      if (was[i] == 0 && workers[i] == 0) {
        was[i] = 1;
        boss[i] = -1;
        cnt++;
      }
  }
  printf("%d\n", m);
  return 0;
}
