#include <bits/stdc++.h>
using namespace std;
int res = 0;
vector<int> maps[2005];
int main(void) {
  void dfs(int u, int deepth);
  int n, value;
  while (scanf("%d", &n) != EOF) {
    memset(maps, 0, sizeof(maps));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &value);
      if (value == -1)
        maps[0].push_back(i);
      else
        maps[value].push_back(i);
    }
    res = 0;
    dfs(0, 0);
    printf("%d\n", res);
  }
  return 0;
}
void dfs(int u, int deepth) {
  res = max(res, deepth);
  for (int i = 0; i < maps[u].size(); i++) {
    dfs(maps[u][i], deepth + 1);
  }
  return;
}
