#include <bits/stdc++.h>
using namespace std;
vector<int> dist(2020, -1);
int n, mx = 0;
vector<int> adj[2020];
vector<bool> visited(2020, false);
void dfs(int s) {
  visited[s] = true;
  for (auto node : adj[s]) {
    dist[node] = dist[s] + 1;
    mx = max(dist[node], mx);
    dfs(node);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x == -1) continue;
    adj[x].push_back(i);
  }
  for (int s = 1; s <= n; ++s) {
    if (visited[s]) continue;
    dist[s] = 0;
    dfs(s);
  }
  cout << mx + 1;
}
