#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4;
int n, ans, par[maxn];
vector<int> g[maxn];
bool vis[maxn];
inline void in() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> par[i];
    par[i]--;
    if (par[i] >= 0) g[par[i]].push_back(i);
  }
}
inline int dfs(int v) {
  int ret = 0;
  for (int i = 0; i < g[v].size(); i++) ret = max(ret, dfs(g[v][i]));
  return ret + 1;
}
inline void solve() {
  for (int i = 0; i < n; i++)
    if (par[i] < 0) ans = max(ans, dfs(i));
}
int main() {
  ios ::sync_with_stdio(0);
  in();
  solve();
  cout << ans << endl;
}
