#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> grafo[2000];
  int min = 0;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a != -1) grafo[i].push_back(a - 1);
  }
  for (int i = 0; i < n; i++) {
    int ram = 1;
    int j = i;
    while (grafo[j].size() == 1) {
      ram++;
      j = grafo[j][0];
    }
    if (min < ram) min = ram;
  }
  cout << min << endl;
}
