#include <bits/stdc++.h>
using namespace std;
int N, P[2005], Ans;
vector<int> AdjList[2005];
int dfs(int u) {
  int height = 0;
  for (auto v : AdjList[u]) height = max(height, dfs(v));
  return height + 1;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &P[i]);
    AdjList[P[i]].push_back(i);
  }
  for (int i = 1; i <= N; i++)
    if (P[i] == -1) Ans = max(Ans, dfs(i));
  printf("%d", Ans);
}
