#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005;
vector<int> g[MAX];
bool used[MAX];
int dfs(int v) {
  used[v] = true;
  int hmax = 1;
  for (int u : g[v]) {
    if (used[u]) continue;
    hmax = max(hmax, dfs(u) + 1);
  }
  return hmax;
}
int32_t main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> root;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    if (p == -1) {
      root.push_back(i);
      continue;
    }
    --p;
    g[i].push_back(p);
    g[p].push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < ((int)root.size()); ++i) ans = max(ans, dfs(root[i]));
  cout << ans;
  return 0;
}
