#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
int n;
vector<int> v;
vector<bool> vis;
int curres = 0;
int solve(int num) {
  int curmax = 0;
  for (int i = 0; i < int(n); i++) {
    if (v[i] == num) {
      curmax = max(curmax, solve(i));
    }
  }
  curmax++;
  return curmax;
}
int main() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < int(n); i++) {
    cin >> v[i];
    if (v[i] != -1) v[i]--;
  }
  vis.assign(n, false);
  for (int i = 0; i < int(n); i++) {
    if (v[i] == -1) curres = max(curres, solve(i));
  }
  cout << curres << endl;
}
