#include <bits/stdc++.h>
using namespace std;
int h[2000];
int p[2000];
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    h[i] = 1;
    p[i] = i;
  }
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a > 0) {
      p[i] = a - 1;
    }
  }
  int mx = 1;
  for (int i = 0; i < n; i++) {
    int cnt = 1;
    int a = i;
    while (p[a] != a) {
      a = p[a];
      cnt++;
    }
    if (cnt > mx) {
      mx = cnt;
    }
  }
  cout << mx;
  return 0;
}
