#include <bits/stdc++.h>
using namespace std;
int ara[2002];
int main() {
  int n, mx = 0, i = 1, ans, temp;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &ara[i]);
  }
  for (i = 0; i < n; i++) {
    temp = ara[i];
    ans = 0;
    while (temp >= 0) {
      temp = ara[temp - 1], ans++;
    }
    mx = max(ans, mx);
  }
  cout << mx + 1;
}
