#include <bits/stdc++.h>
using namespace std;
const int oo = 2047483647;
const int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, c = -oo, u, j;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    j = i, u = 1;
    while (a[j] != -1) j = a[j], u++;
    c = max(u, c);
  }
  cout << c;
  return 0;
}
