#include <bits/stdc++.h>
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 2e3 + 5;
using namespace std;
vector<vector<int>> adj(MAXN);
int mxd;
void dfs(int u, int d) {
  mxd = max(mxd, d);
  for (int v : adj[u]) dfs(v, d + 1);
}
void cp() {
  int n;
  cin >> n;
  vector<int> roots;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    if (p == -1)
      roots.push_back(i);
    else
      adj[p - 1].push_back(i);
  }
  for (int u : roots) dfs(u, 1);
  cout << mxd << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
