#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = 100100;
int n, x, maxdepth;
vector<int> e[N];
void solve(int x, int d) {
  maxdepth = max(maxdepth, d);
  for (int i = 0; i < e[x].size(); i++) solve(e[x][i], d + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x == -1) continue;
    e[i].push_back(x - 1);
  }
  for (int i = 0; i < n; i++) solve(i, 1);
  printf("%d", maxdepth);
  return 0;
}
