import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[][10^^5] T;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (b; 1..N) {
        auto a = readln.chomp.to!int - 1;
        T[a] ~= b;
    }

    int solve(int i) {
        int max_r, max_c;
        foreach (j; T[i]) {
            auto r = solve(j);
            if (r > max_r) {
                max_r = r;
                max_c = 1;
            } else if (r == max_r) {
                ++max_c;
            }
        }
        return max_r + max_c;
    }
    writeln(solve(0));
}