#include <bits/stdc++.h>
using namespace std;
vector<int> a(2001);
int maxi = -1;
int dfs(int src) {
  int temp = src, len = 1;
  while (1) {
    if (a[temp] != -1) {
      len++;
      temp = a[temp];
    } else
      break;
  }
  return len;
}
int main() {
  int n, i, j, k;
  cin >> n;
  for (i = 1; i <= n; i++) {
    int temp;
    cin >> temp;
    a[i] = temp;
  }
  int len;
  for (i = 1; i <= n; i++) {
    len = dfs(i);
    maxi = max(maxi, len);
  }
  cout << maxi << endl;
  return 0;
}
