#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int n, ans, p[N];
vector<int> nei[N];
void dfs(int v, int h = 1) {
  ans = max(ans, h);
  for (int u : nei[v]) dfs(u, h + 1);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] > 0) nei[--p[i]].push_back(i);
  }
  for (int i = 0; i < n; i++)
    if (p[i] == -1) dfs(i);
  cout << ans;
  return 0;
}
