#include <bits/stdc++.h>
using namespace std;
long long n;
long long p[2003];
long long level[2003];
long long deg[2003];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    cin >> n;
    for (long long i = 0; i < n; ++i) {
      cin >> p[i];
      if (p[i] > 0) {
        p[i]--;
      }
      if (p[i] >= 0) deg[p[i]]++;
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        if (deg[j] == 0) {
          deg[j] = 1;
          if (p[j] >= 0) {
            level[p[j]] = max(level[p[j]], level[j] + 1);
            deg[p[j]]--;
          }
        }
      }
    }
    long long ans = 0;
    for (long long i = 0; i < n; ++i) {
      if (level[i] + 1 > ans) {
        ans = level[i] + 1;
      }
    }
    cout << ans;
  }
}
