import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
auto solve(string s_) {
    immutable N = s_.to!int();
    auto a = new int[][N];
    foreach(i;1..N) a[readln.chomp.to!int()-1]~=i;
    int dfs(int i) {
        int m=0;
        foreach(int k,v;a[i].map!dfs().array().sort!"a>b"().array())
            m=max(m,k+v+1);
        return m;
    }
    return dfs(0);
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }