#include <bits/stdc++.h>
using namespace std;
const int64_t inf = 1e18;
vector<vector<int64_t> > adj;
int64_t inp() {
  int64_t x;
  cin >> x;
  return x;
}
vector<int64_t> level;
int64_t res = 0;
void dfs(int64_t u, int64_t LV = 0) {
  level[u] = LV;
  res = max(res, LV);
  for (auto v : adj[u]) {
    dfs(v, LV + 1);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int64_t _ = (1); _ >= (1); _--) {
    int64_t n;
    cin >> n;
    adj.resize(n + 1);
    level.resize(n + 1);
    for (int64_t node = (1); node <= (n); node++)
      adj[max(inp(), int64_t(0))].push_back(node);
    dfs(0);
    cout << res;
  }
  return 0;
}
