#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, t, j;
  int p[2005], d[2005];
  vector<int> adj[2005];
  while (cin >> n) {
    for (i = 1; i <= n; i++) {
      cin >> p[i];
      if (p[i] != -1) {
        adj[p[i]].push_back(i);
      }
    }
    for (i = 1; i <= n; i++) {
      if (p[i] == -1) {
        queue<int> Q;
        Q.push(i);
        d[i] = 0;
        while (!Q.empty()) {
          t = Q.front();
          Q.pop();
          for (j = 0; j < adj[t].size(); j++) {
            Q.push(adj[t][j]);
            d[adj[t][j]] = d[t] + 1;
          }
        }
      }
    }
    int mx = 0;
    for (i = 1; i <= n; i++) {
      mx = max(mx, d[i]);
    }
    cout << mx + 1 << endl;
  }
  return 0;
}
