#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 1e3 + 2;
const long long int mod = 1e3 + 2;
vector<long long int> v[2003];
vector<bool> visited(2003, 0);
vector<long long int> depth(2003, 1);
vector<long long int> parent(2003, 0);
void dfs(long long int c) {
  for (long long int j = 0; j < v[c].size(); j++) {
    if (!visited[v[c][j]]) {
      visited[v[c][j]] = 1;
      depth[v[c][j]] = depth[c] + 1;
      dfs(v[c][j]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, a, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (a != -1) {
      v[a].push_back(i);
    }
    parent[i] = a;
  }
  for (i = 1; i <= n; i++) {
    if (parent[i] == -1) {
      depth[i] = 1;
      visited[i] = 1;
      dfs(i);
    }
  }
  long long int ans = 0;
  for (i = 1; i <= n; i++) ans = max(ans, depth[i]);
  cout << ans;
}
