#include <bits/stdc++.h>
using namespace std;
vector<int> arr[2005];
bool mark[2005];
int groups = 0;
void dfs(int nodo, int count) {
  groups = max(count, groups);
  for (auto x : arr[nodo]) {
    dfs(x, count + 1);
  }
}
int main() {
  int n, a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a < 0)
      mark[i] = 1;
    else
      arr[a].push_back(i);
  }
  int maximo = -1;
  for (int i = 1; i <= n; i++) {
    if (mark[i]) dfs(i, 1);
    maximo = max(groups, maximo);
  }
  printf("%d\n", maximo);
}
