#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f3f;
const int N = 2e3 + 5;
int dep[N], p[N];
vector<int> g[N];
void dfs(int u) {
  for (auto v : g[u]) {
    dep[v] = dep[u] + 1;
    dfs(v);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    if (~p[i]) g[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == -1) dep[i] = 1, dfs(i);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    res = max(res, dep[i]);
  }
  printf("%d\n", res);
  return 0;
}
