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