#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n;
vector<int> g[N];
int l = 1;
void DFS(int u, int level) {
  l = max(l, level);
  for (auto x : g[u]) {
    DFS(x, level + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x != -1) g[x].push_back(i + 1);
  }
  for (int i = 1; i <= n; i++) {
    DFS(i, 1);
  }
  cout << l;
}
