#include <bits/stdc++.h>
using namespace std;
long long p[2001];
long long find_size(long long x) {
  if (p[x] == -1) return 1;
  return 1 + find_size(p[x]);
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x > 0) x--;
    p[i] = x;
  }
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    ans = max(ans, find_size(i));
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
