#include <bits/stdc++.h>
using namespace std;
const int N = 2007;
vector<int> adj[N];
int dis[N], arr[N], ans = 0;
void bfs(int root) {
  queue<int> q;
  dis[root] = 0;
  q.push(root);
  while (!q.empty()) {
    int CurrentNode = q.front();
    q.pop();
    for (auto i : adj[CurrentNode]) {
      q.push(i);
      dis[i] = dis[CurrentNode] + 1;
      ans = max(dis[i], ans);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
    if (arr[i] == -1) continue;
    adj[arr[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) bfs(i);
  cout << ans + 1;
  return 0;
}
