#include <bits/stdc++.h>
using namespace std;
int n, p[2001], k, m = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) {
    int c = 1;
    k = p[i];
    while (k > 0) {
      k = p[k - 1];
      c++;
    }
    m = max(c, m);
  }
  cout << m;
}
