#include <bits/stdc++.h>
using namespace std;
int max_level = 0;
vector<int> tree[2010];
int dfs(int n, int level) {
  if (tree[n].empty()) {
    max_level = max(max_level, level);
    return 0;
  }
  for (auto u : tree[n]) {
    dfs(u, level + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x != -1) {
      tree[x].push_back(i);
    } else {
      tree[0].push_back(i);
    }
  }
  for (auto u : tree[0]) {
    dfs(u, 1);
  }
  cout << max_level;
  return 0;
}
