#include <bits/stdc++.h>
using namespace std;
vector<int> adjList[2005];
vector<int> bosses;
bool color[2005] = {
    0,
};
int maxx = 0;
void dfs(int node, int level);
void dfs(int node, int level) {
  int newLevel = level + 1;
  maxx = (maxx >= newLevel ? maxx : newLevel);
  for (int i = 0; i < adjList[node].size(); i++) {
    dfs(adjList[node][i], newLevel);
  }
}
int main() {
  int N;
  int i, u;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &u);
    if (u == -1) {
      bosses.push_back(i);
    } else {
      u--;
      adjList[u].push_back(i);
    }
  }
  for (i = 0; i < bosses.size(); i++) {
    dfs(bosses[i], 0);
  }
  printf("%d\n", maxx);
  return 0;
}
