#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 3e5 + 5, M = N;
vector<int> g[2010];
bool vis[2020];
int level[2020];
int bfs(int src) {
  queue<int> q;
  q.push(src);
  vis[src] = 1;
  level[src] = 1;
  int mx = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : g[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        level[v] = level[u] + 1;
        mx = max(mx, level[v]);
        q.push(v);
      }
    }
  }
  return mx;
}
void solve() {
  int n, m, u;
  scanf("%d", &n);
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &u);
    if (u != -1) {
      g[u].push_back(i);
      g[i].push_back(u);
    } else
      v.push_back(i);
  }
  int res = 0, sz = v.size();
  for (int i = 0; i < sz; i++) {
    res = max(res, bfs(v[i]));
  }
  printf("%d\n", res);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
