#include <bits/stdc++.h>
using namespace std;
const int N = 2123;
int n, ans = 0;
vector<int> g[N], start;
bool used[N];
void dfs(int v, int h) {
  used[v] = true;
  ans = max(ans, h);
  for (auto i : g[v])
    if (!used[i]) dfs(i, h + 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int v;
    cin >> v;
    if (v == -1)
      start.push_back(i);
    else
      g[v].push_back(i);
  }
  for (auto i : start)
    if (!used[i]) dfs(i, 1);
  cout << ans;
  return 0;
}
