#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2E9;
const long long LINF = (long long)9E18;
const long double PI = acos(-1.0);
const long double EPS = 1E-11;
long long n;
long long a[2001], color[2001], bac[2001], sl[2001];
long long ke[2001][2001];
void doc() {
  long long i, u;
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    cin >> u;
    if (u != -1) {
      sl[u]++;
      ke[u][sl[u]] = i;
    }
  }
}
void dfs(long long u) {
  long long i, v;
  color[u] = 1;
  for (i = 1; i <= sl[u]; i++) {
    v = ke[u][i];
    bac[v] = bac[u] + 1;
    dfs(v);
  }
}
void tinh() {
  long long i, kq;
  for (int i = 1; i <= (n); ++i) {
    if (color[i] == 0) {
      bac[i] = 1;
      dfs(i);
    }
  }
  kq = 0;
  for (int i = 1; i <= (n); ++i) {
    if (bac[i] > kq) kq = bac[i];
  }
  cout << kq;
}
int main() {
  doc();
  tinh();
  return 0;
}
