#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, ans = 0;
  cin >> n;
  int a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    int c = 0;
    int k = a[i];
    while (k > 0) {
      k = a[k];
      c++;
    }
    ans = max(c, ans);
  }
  cout << ans + 1 << endl;
  return 0;
}
