#include <bits/stdc++.h>
using namespace std;
void mytimer(string task) {}
bool s[2020];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  int p[2020];
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> p[i];
    if (p[i] > 0) p[i]--;
  }
  int cnt = 0;
  int check = true;
  while (check) {
    check = false;
    for (int i = 0; i < (n); ++i)
      if ((p[i] != -2) && ((p[i] == -1) || (p[p[i]] == -2))) {
        check = true;
        s[i] = true;
      }
    for (int i = 0; i < (n); ++i)
      if (s[i]) p[i] = -2;
    if (check) cnt++;
  }
  cout << cnt;
  return 0;
}
