#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int N = 2222;
vector<int> g[N];
vector<int> root;
int n;
int resp;
void dfs(int x, int s, int prof) {
  resp = max(resp, prof);
  for (int i = 0; i < g[x].size(); ++i) {
    int y = g[x][i];
    if (y != s) dfs(y, x, prof + 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == -1) {
      root.push_back(i);
      continue;
    }
    x--;
    g[x].push_back(i);
  }
  resp = 0;
  for (int i = 0; i < root.size(); ++i) dfs(root[i], -1, 1);
  printf("%d\n", resp);
  return 0;
}
