#include <bits/stdc++.h>
using namespace std;
vector<int> tree[2100];
bool flag[2100];
int n;
int ans;
void dfs(int i, int d) {
  flag[i] = true;
  ans = d > ans ? d : ans;
  for (int j = 0; j < tree[i].size(); j++) {
    dfs(tree[i][j], d + 1);
  }
}
int main(int argc, char* argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) tree[i].clear();
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d", &p);
    if (p > 0) tree[p].push_back(i);
  }
  ans = 1;
  memset(flag, 0, sizeof(flag));
  for (int i = 1; i <= n; i++)
    if (!flag[i]) dfs(i, 1);
  printf("%d\n", ans);
  return 0;
}
