#include <bits/stdc++.h>
using namespace std;
vector<int> tree[2005];
vector<int> v;
int mx;
void dfs(int cur, int d) {
  mx = max(mx, d);
  for (auto g : tree[cur]) {
    dfs(g, d + 1);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x != -1) tree[x].push_back(i);
    if (x == -1) v.push_back(i);
  }
  for (auto i : v) {
    dfs(i, 0);
  }
  cout << mx + 1;
}
