#include <bits/stdc++.h>
using namespace std;
int res;
int d[2000];
vector<vector<int>> g;
void bfs(int u) {
  d[u] = 0;
  queue<int> Q;
  Q.push(u);
  while (!Q.empty()) {
    int v = Q.front();
    res = max(res, d[v]);
    Q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int u = g[v][i];
      if (d[u] == -1) {
        d[u] = d[v] + 1;
        Q.push(u);
      }
    }
  }
  return;
}
int main() {
  int n;
  cin >> n;
  res = -1000000000;
  g.resize(n);
  for (int i = 0; i < n; i++) {
    int j;
    cin >> j;
    if (j == -1) continue;
    j--;
    g[j].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    memset(d, -1, sizeof(d));
    bfs(i);
  }
  cout << res + 1;
  return 0;
}
