#include <bits/stdc++.h>
const int N = 2e3, MOD = 1000000007;
using namespace std;
int n, p, ans, dis[N + 9];
vector<int> ch[N + 9];
int DFS(int node) {
  if (dis[node]) return dis[node];
  int ret = 1;
  for (int child : ch[node]) ret = max(ret, 1 + DFS(child));
  return dis[node] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p);
    if (p != -1) ch[p].push_back(i);
  }
  for (int i = 1; i <= n; ++i) ans = max(ans, DFS(i));
  printf("%d\n", ans);
  return 0;
}
