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