#include <bits/stdc++.h>
using namespace std;
vector<int> ady[2005];
bool seen[2005];
int maxi;
void dfs(int x, int d) {
  maxi = max(maxi, d);
  seen[x] = 1;
  for (int i = 0; i < ady[x].size(); ++i) {
    if (!seen[ady[x][i]]) {
      dfs(ady[x][i], d + 1);
    }
  }
}
int main() {
  int n, p;
  scanf("%d", &n);
  vector<int> root;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p);
    if (p == -1)
      root.push_back(i);
    else
      ady[p].push_back(i);
  }
  maxi = 0;
  for (int i = 0; i < root.size(); ++i) {
    dfs(root[i], 1);
  }
  printf("%d\n", maxi);
  return 0;
}
