#include <bits/stdc++.h>
using namespace std;
vector<int> e[2000];
map<int, int> h;
map<int, bool> mark;
int mx = 0;
int hight(int v) {
  if (!mark[v]) {
    if (e[v][0] == -1)
      h[v] = 1;
    else
      h[v] = hight(e[v][0]) + 1;
    if (h[v] > mx) mx = h[v];
    mark[v] = true;
  }
  return h[v];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    if (m == -1)
      e[i].push_back(-1);
    else
      e[i].push_back(--m);
  }
  for (int i = 0; i < n; i++) hight(i);
  cout << mx;
  return 0;
}
