#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2020;
vector<int> g[MAXN];
int maxDep = -1;
void DFS(int v, int depth) {
  if (depth > maxDep) maxDep = depth;
  for (int i = 0; i < g[v].size(); i++) DFS(g[v][i], depth + 1);
}
int main() {
  int n, a;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a != -1) g[i].push_back(a);
  }
  for (int i = 1; i <= n; i++) DFS(i, 1);
  cout << maxDep << endl;
  return 0;
}
