#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, k, l, n, ans = 0;
  cin >> n;
  vector<int> v[3000];
  for (i = 1; i <= n; i++) {
    cin >> k;
    v[k].push_back(i);
  }
  queue<int> q, C;
  for (i = 1; i <= n; i++) {
    q.push(i);
    C.push(1);
    while (!q.empty()) {
      k = q.front();
      int count = C.front();
      if (count > ans) ans = count;
      C.pop();
      q.pop();
      int h = v[k].size();
      for (l = 0; l < h; l++) {
        q.push(v[k][l]);
        C.push(count + 1);
      }
    }
  }
  cout << ans;
  return 0;
}
