#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 10;
vector<int> adj[MAXN];
int ans;
void DFS(int v, int l) {
  for (int i : adj[v]) DFS(i, l + 1);
  ans = max(l, ans);
}
int main() {
  int n;
  cin >> n;
  vector<int> sup;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x == -1) {
      sup.push_back(i);
      continue;
    }
    adj[x].push_back(i);
  }
  for (int i : sup) DFS(i, 0);
  cout << ans + 1 << '\n';
}
