#include <bits/stdc++.h>   using namespace std;   int n, p[3000], k, m = 0, c;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       k = p[i];       c = 1;       while (k > 0) {         c++;         k = p[k];       }       m = max(c, m);     }     cout << m;     return 0;   }   