import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.
lang.
Math.
*; import static java.
util.
Arrays.
*;
public class A{
Scanner sc
=new Scanner
(System.
in);
int INF=1<<28;
double EPS=1e-9;
int n;
int[] p;
void run(){
n=sc.nextInt();
p=new int[n];
for(int i=0; i<n; i++){
p[i]=sc.nextInt();
if(p[i]>0){
p[i]--;
}
}
int ans=0;
for(int i=0; i<n; i++){
int c=0;
for(int v=i; v>=0; v=p[v]){
c++;
}
ans=max(ans, c);
}
println(ans+"");
}
}
}
}
public static void main
(String[] args
){ new A().run();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLm1hdGguKjsKaW1wb3J0IGphdmEuaW8uKjsKCmltcG9ydCBzdGF0aWMgamF2YS5sYW5nLk1hdGguKjsKaW1wb3J0IHN0YXRpYyBqYXZhLnV0aWwuQXJyYXlzLio7CgpwdWJsaWMgY2xhc3MgQXsKCVNjYW5uZXIgc2M9bmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCglpbnQgSU5GPTE8PDI4OwoJZG91YmxlIEVQUz0xZS05OwoKCWludCBuOwoJaW50W10gcDsKCgl2b2lkIHJ1bigpewoJCW49c2MubmV4dEludCgpOwoJCXA9bmV3IGludFtuXTsKCQlmb3IoaW50IGk9MDsgaTxuOyBpKyspewoJCQlwW2ldPXNjLm5leHRJbnQoKTsKCQkJaWYocFtpXT4wKXsKCQkJCXBbaV0tLTsKCQkJfQoJCX0KCQlpbnQgYW5zPTA7CgkJZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKCQkJaW50IGM9MDsKCQkJZm9yKGludCB2PWk7IHY+PTA7IHY9cFt2XSl7CgkJCQljKys7CgkJCX0KCQkJYW5zPW1heChhbnMsIGMpOwoJCX0KCQlwcmludGxuKGFucysiIik7Cgl9CgoJdm9pZCBwcmludGxuKFN0cmluZyBzKXsKCQlTeXN0ZW0ub3V0LnByaW50bG4ocyk7Cgl9CgoJdm9pZCBwcmludChTdHJpbmcgcyl7CgkJU3lzdGVtLm91dC5wcmludChzKTsKCX0KCgl2b2lkIGRlYnVnKE9iamVjdC4uLiBvcyl7CgkJU3lzdGVtLmVyci5wcmludGxuKEFycmF5cy5kZWVwVG9TdHJpbmcob3MpKTsKCX0KCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKXsKCQluZXcgQSgpLnJ1bigpOwoJfQp9