#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
bool mark[maxn];
vector<int> adj[maxn];
int h[maxn], par[maxn], maxh;
void dfs(int v) {
  mark[v] = true;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int u = adj[v][i];
    if (!mark[u]) {
      h[u] = h[v] + 1;
      maxh = max(maxh, h[u]);
      dfs(u);
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u;
    cin >> u;
    par[i] = u;
    if (u == -1) continue;
    par[i]--;
    u--;
    adj[u].push_back(i), adj[i].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i] && par[i] == -1) {
      h[i] = 1;
      dfs(i);
    }
  }
  if (maxh < 1) maxh = 1;
  cout << maxh << endl;
  return 0;
}
