#include <bits/stdc++.h>
using namespace std;
vector<int> v[2005];
int vis[2005];
int mx = 0;
void dfs(int n, int c) {
  if (v[n].size() == 0 || vis[n] != -1) {
    return;
  }
  vis[n] = 0;
  c++;
  mx = max(mx, c);
  for (int i = 0; i < v[n].size(); i++) {
    if (vis[v[n][i]] == -1) {
      dfs(v[n][i], c);
    }
  }
  return;
}
int main() {
  memset(vis, -1, sizeof(vis));
  int n, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x != -1) {
      v[i].push_back(x);
    }
  }
  for (int i = 1; i <= n; i++) {
    memset(vis, -1, sizeof(vis));
    dfs(i, 0);
  }
  cout << mx + 1 << endl;
  return 0;
}
