@staticmethod
def c():
    (n, *b) = map(int, sys.stdin.read().split())
    g = GeometryTopology.Graph()
    for i in range(1, n):
        g.add_edge((b[(i - 1)] - 1), i, weight=1)

    def f(u=0):
        if (not g.edges[u]):
            return 1
        s = [f(v) for v in g.edges[u]]
        return ((max(s) + min(s)) + 1)
    print(f())
@staticmethod
def c():
    (n, *b) = map(int, sys.stdin.read().split())
    g = GeometryTopology.Graph()
    for i in range(1, n):
        g.add_edge((b[(i - 1)] - 1), i, weight=1)

    def f(u=0):
        if (not g.edges[u]):
            return 1
        s = [f(v) for v in g.edges[u]]
        return ((max(s) + min(s)) + 1)
    print(f())