#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
using namespace std;
const long long INF = 2e18;
const long double PI = acos(-1);
const long long MOD = 1e9 + 7;
const long long MAXN = 2001;
vector<vector<long long> > g(MAXN);
long long bfs(long long root) {
  long long res = 1;
  vector<long long> d(MAXN);
  queue<long long> q;
  d[root] = 1;
  q.push(root);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (auto v : g[u]) {
      d[v] = d[u] + 1;
      res = max(res, d[v]);
      q.push(v);
    }
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> roots;
  long long ans = 0;
  for (int v = 1; v <= n; ++v) {
    long long u;
    cin >> u;
    if (u != -1)
      g[u].push_back(v);
    else
      roots.push_back(v);
  }
  for (long long root : roots) ans = max(ans, bfs(root));
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
