import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int n;
    scan(n);

    auto tree = new int[][](n);

    foreach (i ; 1 .. n) {
        int ai;
        scan(ai);
        tree[ai-1] ~= i;
    }

    int dfs(int v) {
        if (tree[v].empty) {
            return 0;
        }

        auto d = new int[](tree[v].length);

        foreach (i, ch ; tree[v]) {
            d[i] = dfs(ch);
        }

        d.sort!"a > b"();

        int res;

        foreach (i, di; d) {
            res = max(res, di + i + 1);
        }

        return res;
    }

    writeln(dfs(0));
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}