#include <bits/stdc++.h>
using namespace std;
vector<int> g[2001];
bool used[2001];
int mx = 0;
void dfs(int a, int f) {
  used[a] = 1;
  for (int i = 0; i < g[a].size(); ++i) {
    int to = g[a][i];
    if (!used[to]) {
      dfs(to, f + 1);
    }
  }
  mx = max(mx, f);
}
int main() {
  vector<int> v;
  int n;
  cin >> n;
  int a;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if (a == -1) {
      v.push_back(i);
    } else {
      g[a].push_back(i);
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    dfs(v[i], 1);
  }
  cout << mx;
}
