#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> tree[2010];
int dfs(int pos) {
  int ret = 0;
  for (int i = 0; i < tree[pos].size(); i++)
    ret = max(ret, 1 + dfs(tree[pos][i]));
  return ret;
}
int main() {
  scanf("%d", &n);
  vector<int> allah;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x == -1)
      allah.push_back(i);
    else {
      x--;
      tree[x].push_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < allah.size(); i++) ans = max(ans, 1 + dfs(allah[i]));
  printf("%d\n", ans);
}
