#include <bits/stdc++.h>
using namespace std;
const int maxn = 2050;
vector<int> buf[maxn];
int p[maxn];
int n;
int dfs(int x) {
  int res = 1;
  for (auto it = (buf[x]).begin(); it != (buf[x]).end(); ++it)
    res = max(res, dfs(*it) + 1);
  return res;
}
int main(void) {
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    cin >> p[i];
    if (p[i] < 0) p[i] = 0;
    buf[p[i]].push_back(i);
  }
  cout << dfs(0) - 1 << endl;
}
