#include <bits/stdc++.h>
using namespace std;
vector<int> graph[2010];
int vis[2010], depth[2010];
int n;
int dfs(int u) {
  vis[u] = 1;
  int& ans = depth[u];
  for (int v : graph[u]) {
    ans = max(ans, dfs(v) + 1);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    vis[i] = 0, depth[i] = 1;
    int d;
    cin >> d;
    if (d == -1) continue;
    graph[d].push_back(i);
  }
  for (int i = 1; i <= n; ++i) dfs(i);
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, depth[i]);
  cout << ans;
  return 0;
}
