#include <bits/stdc++.h>
using namespace std;
int ans = 1, n, x, dept[2005];
vector<int> v[2005];
int dfs(int node) {
  int cev = 1;
  if (dept[node]) return dept[node];
  for (int i = 0; i <= (int)v[node].size() - 1; i++) {
    cev = max(cev, dfs(v[node][i]) + 1);
  }
  return dept[node] = cev;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x != -1) v[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (!dept[i]) {
      ans = max(ans, dfs(i));
    }
  }
  printf("%d", ans);
}
