#include <bits/stdc++.h>
using namespace std;
vector<int> v[2003];
int depth[2003], root[2003];
int ans = 0, n;
void dfs(int x, int y) {
  depth[x] = y;
  for (int i = 0; i < v[x].size(); i++) {
    dfs(v[x][i], y + 1);
  }
}
int main() {
  int i, j, a;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (a == -1)
      root[i] = 1;
    else
      v[a].push_back(i);
  }
  for (i = 1; i <= n; i++) {
    if (root[i]) dfs(i, 1);
  }
  for (i = 1; i <= n; i++) {
    ans = max(ans, depth[i]);
  }
  cout << ans;
  return 0;
}
