#include <bits/stdc++.h>
using namespace std;
int tree[2001];
int get(int ind) {
  if (ind < 0) return 0;
  return 1 + get(tree[ind]);
}
int main() {
  int N;
  scanf("%d", &N);
  int t = N;
  for (int i = 0; i < N; i++) scanf("%d", &tree[i + 1]);
  int mx = 0;
  for (int i = 1; i <= N; i++) mx = max(mx, get(i));
  cout << mx << endl;
  return 0;
}
