#include <bits/stdc++.h>
using namespace std;
int a[2005];
int c;
void root(int x) {
  c++;
  if (a[x] == -2) return;
  root(a[x]);
}
int main() {
  int n, maxm = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] -= 1;
  }
  for (int i = 0; i < n; i++) {
    c = 0;
    root(i);
    maxm = max(maxm, c);
  }
  cout << maxm;
  return 0;
}
