#include <bits/stdc++.h>
using namespace std;
vector<int> adj[2005];
vector<int> managers;
bool visited[2005];
int dfs(int u) {
  visited[u] = true;
  int mxHeight = 0;
  for (int v : adj[u]) {
    if (visited[v] == false) {
      mxHeight = max(mxHeight, dfs(v));
    }
  }
  return 1 + mxHeight;
}
int main() {
  int n, p;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    if (p == -1) {
      managers.emplace_back(i);
      continue;
    }
    adj[i].emplace_back(p);
    adj[p].emplace_back(i);
  }
  int mx = INT_MIN;
  for (int manager : managers) {
    mx = max(mx, dfs(manager));
  }
  cout << mx << endl;
  return 0;
}
