#include <bits/stdc++.h>
using namespace std;
int n, maks = 0, dl = 0, zm;
int tab[2005];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> tab[i];
  for (int i = 0; i < n; i++) {
    dl = 1;
    zm = tab[i];
    while (zm != -1) {
      zm = tab[zm - 1];
      dl++;
    }
    maks = max(maks, dl);
  }
  cout << maks;
  return 0;
}
