#include <bits/stdc++.h>
using namespace std;
int const N = 2e3 + 5;
int n, u, x, Mx, temp;
bool vis[N];
set<pair<int, int> > ps;
set<int> res;
vector<int> adj[N];
int dfs(int u) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (!vis[v]) x++;
    dfs(v);
  }
  return x;
}
void DFS(int u, int c) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (!vis[v]) DFS(v, c + 1);
  }
  res.insert(c);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &u);
    if (u != -1) {
      u--;
      adj[u].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    x = 0;
    memset(vis, 0, sizeof vis);
    dfs(i);
    ps.insert(make_pair(-1 * x, i));
  }
  memset(vis, 0, sizeof vis);
  for (auto i : ps) {
    if (!vis[i.second]) DFS(i.second, 1);
  }
  printf("%d", *res.end());
}
