#include <bits/stdc++.h>
using namespace std;
vector<int> g[2009];
int depth[2009];
void dfs(int nd, int p, int dpt = 1) {
  depth[nd] = dpt;
  for (auto ch : g[nd])
    if (ch == p)
      continue;
    else
      dfs(ch, nd, dpt + 1);
}
int main() {
  int n;
  cin >> n;
  vector<int> roots;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x == -1) {
      roots.push_back(i);
      continue;
    }
    g[i].push_back(x);
    g[x].push_back(i);
  }
  for (auto rt : roots) dfs(rt, -1);
  int ans = 1;
  for (int i = 1; i <= n; ++i) ans = max(ans, depth[i]);
  cout << ans << endl;
  return 0;
}
