#include <bits/stdc++.h>
using namespace std;
long int a[2000], n, m, i, j, k, l, x, y;
queue<long int> q;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != -1) {
      a[i]--;
    }
  }
  m = 1;
  x = 0;
  y = 0;
  for (i = 0; i < n; i++) {
    x = i;
    y = 1;
    while (a[x] != -1) {
      x = a[x];
      y++;
    }
    if (y > m) {
      m = y;
    }
  }
  cout << m;
  return 0;
}
