#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int a[maxn];
int f(int p) {
  if (a[p] == -1) return 1;
  return f(a[p]) + 1;
}
int main() {
  int n, best = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  best = 0;
  for (int i = 1; i <= n; i++)
    if (f(i) > best) best = f(i);
  cout << best << endl;
}
