#include <bits/stdc++.h>
using namespace std;
int ll;
vector<int> v[2005];
void dfs(int in, int d) {
  ll = max(ll, d);
  for (int i = 0; i < v[in].size(); i++) dfs(v[in][i], d + 1);
}
int main() {
  int n;
  cin >> n;
  ll = 0;
  vector<int> p;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x == -1)
      p.push_back(i);
    else
      v[x].push_back(i);
  }
  for (int i = 0; i < p.size(); i++) dfs(p[i], 1);
  cout << ll << "\n";
  return 0;
}
