#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, arr[2001], max = 1, count, j;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> arr[i];
  for (i = 1; i <= n; ++i) {
    count = 1;
    j = i;
    while (arr[j] != -1) {
      ++count;
      j = arr[j];
    }
    if (count > max) max = count;
  }
  cout << max;
  return 0;
}
