#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int>pi;
typedef pair<ll, ll>pl;
typedef vector<pi>vpi;
typedef vector<pl>vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
const long double PI = acos(-1);
const ll oo = LLONG_MAX;
const int MOD = 1e9 + 7;
const int N = 2e3 + 7;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define read(v) for (auto& it : v) scanf("%d", &it);
#define readl(v) for (auto& it : v) scanf("%lld", &it);
#define print(v) for (auto it : v) printf("%d ", it); puts("");
#define printl(v) for (auto it : v) printf("%lld ", it); puts("");
int n, ans = 0;
vector<vector<int>>g(N);
void DFS(int u, int dep) {
ans = max(ans, dep);
for (auto& v : g[u])
DFS(v, dep + 1);
}
void init() {
ans = 0;
for (int i = 0; i <= n; i++)
g[i].clear();
}
void solve() {
scanf("%d", &n);
init();
vector<int>p(n);
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
if (p[i] != -1) {
p[i]--;
g[p[i]].push_back(i);
}
}
for (int i = 0; i < n; i++)
if (p[i] == -1)
DFS(i, 0);
printf("%d\n", ans + 1);
}
int t = 1;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//scanf("%d", &t);
while (t--) solve();
}
77u/I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4JCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIGxvbmcgZG91YmxlIGxkOwp0eXBlZGVmIHZlY3RvcjxpbnQ+IHZpOwp0eXBlZGVmIHZlY3RvcjxsbD4gdmw7CnR5cGVkZWYgcGFpcjxpbnQsIGludD5waTsKdHlwZWRlZiB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