#include <bits/stdc++.h>
using namespace std;
int n, p, kol, ans;
bool used[2005];
vector<int> a[2005];
void dfs(int v) {
  kol++;
  used[v] = 1;
  for (int i = 0; i < a[v].size(); i++)
    if (!used[a[v][i]]) dfs(a[v][i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p);
    if (p == -1) continue;
    p--;
    a[i].push_back(p);
  }
  for (int i = 0; i < n; i++) {
    kol = 0;
    memset(used, 0, sizeof used);
    dfs(i);
    ans = max(kol, ans);
  }
  printf("%d\n", ans);
  return 0;
}
