#include <bits/stdc++.h>
int h[2000];
int p[2000];
int n;
int f(int i) {
  if (h[i] >= 0) return h[i];
  if (p[i] < 0) return 1;
  return h[i] = f(p[i]) + 1;
}
int main() {
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> p[i];
    --p[i];
    h[i] = -1;
  }
  int m = 0, m1;
  for (int i = 0; i < n; ++i) {
    m1 = f(i);
    if (m1 > m) m = m1;
  }
  std::cout << m << "\n";
  return 0;
}
