#include <bits/stdc++.h>
using namespace std;
const int N = 150, M = 150, OO = 0x3f3f3f3f;
int n, arr[2005], temp, ans;
void DFS(int u) {
  temp++;
  if (arr[u] == -1) return;
  DFS(arr[u]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", arr + i);
  }
  for (int i = 1; i <= n; ++i) {
    temp = 0;
    DFS(i);
    ans = max(ans, temp);
  }
  printf("%d\n", ans);
  return 0;
}
