#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
vector<int> adj[N];
vector<int> depth(N, -1);
int n;
void dfs(int src, int s) {
  if (src == s) depth[src] = 1;
  for (auto x : adj[src]) {
    depth[x] = 1 + depth[src];
    dfs(x, s);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x != -1) adj[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (depth[i] == -1) dfs(i, i);
  }
  cout << *max_element(depth.begin(), depth.end()) << '\n';
  return 0;
}
