#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX;
const int base = 1e9 + 7;
const int maxn = 1e5 + 1;
const int mod = 1e9 + 7;
vector<int> adj[2002];
bool visited[2002];
int n, tmp, mx = 0, cnt = 0;
void dfs(int s, int cnt) {
  if (visited[s]) return;
  visited[s] = 1;
  cnt++;
  if (adj[s].empty()) mx = max(mx, cnt);
  for (auto u : adj[s]) dfs(u, cnt);
}
signed main() {
  memset(visited, 0, sizeof visited);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    if (tmp == -1)
      adj[0].emplace_back(i);
    else
      adj[tmp].emplace_back(i);
  }
  for (auto s : adj[0]) dfs(s, 0);
  cout << mx;
}
