#include <bits/stdc++.h>   using namespace std;   int p[2222], n;   int D[2222];   int Find(int x) {     if (D[x] != 0) return D[x];     if (p[x] == -1)       return D[x] = 1;     else       return D[x] = Find(p[x]) + 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     int ans = 0, tmp;     for (int i = 1; i <= n; i++) {       tmp = Find(i);       if (tmp > ans) ans = tmp;     }     printf( %d n , ans);     return 0;   }   