#include <bits/stdc++.h>
using namespace std;
vector<int> sir;
vector<int> em[2001];
int group;
int n, x;
void dfs(int k, int g) {
  group = max(group, g);
  for (int i = 0; i < em[k].size(); i++) {
    dfs(em[k][i], g + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == -1) {
      sir.push_back(i);
    } else {
      em[x].push_back(i);
    }
    group = 1;
    for (int i = 0; i < sir.size(); i++) {
      dfs(sir[i], 1);
    }
  }
  cout << group << endl;
}
