#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
const int INF = 1e9 + 7;
const int MAXN = int(3e5 + 7);
int n, a[2007], ans;
vector<int> g[2007];
int dfs(int v) {
  int maxi = 0;
  for (int i = 0; i < g[v].size(); i++) maxi = max(maxi, dfs(g[v][i]));
  return maxi + 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) g[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) ans = max(ans, dfs(i));
  }
  cout << ans;
  return 0;
}
