#include <bits/stdc++.h>
using namespace std;
int d[2010];
int p[2010];
int res = 1;
int dfs(int i) {
  if (d[i] > 0) {
    return d[i];
  }
  int m = p[i];
  if (m == -1) {
    d[i] = 1;
    return d[i];
  }
  m--;
  d[i] = 1 + dfs(m);
  res = max(res, d[i]);
  return d[i];
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    dfs(i);
  }
  cout << res << endl;
  return 0;
}
