#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
int e[2020];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int first;
    cin >> first;
    e[i] = first;
  }
  int mx = 1;
  for (int i = 1; i <= n; i++) {
    int m = i;
    int kmx = 0;
    while (true) {
      m = e[m];
      kmx++;
      if (m == 0 || m == -1) break;
    }
    mx = max(mx, kmx);
  }
  cout << mx << endl;
}
