#AGC009B. Tournament

Tournament

Score : 800800 points

Problem Statement

NN contestants participated in a competition. The total of N1N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.

After each match, there were always one winner and one loser. The last contestant standing was declared the champion.

Figure: an example of a tournament

For convenience, the contestants were numbered 11 through NN. The contestant numbered 11 was the champion, and the contestant numbered i(2iN)i(2 \leq i \leq N) was defeated in a match against the contestant numbered aia_i.

We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.

Find the minimum possible depth of the tournament.

The formal description of the structure of the tournament is as follows. In the ii-th match, one of the following played against each other:

  • Two predetermined contestants
  • One predetermined contestant and the winner of the jj-th match, where $j(j was predetermined
  • The winner of the jj-th match and the winner of the kk-th match, where jj and kk $(j,k were predetermined

Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1aiN(2iN)1 \leq a_i \leq N(2 \leq i \leq N)
  • It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).

Input

The input is given from Standard Input in the following format:

NN

a2a_2

:

aNa_N

Output

Print the minimum possible depth of the tournament.

5
1
1
2
4
3

The following tournament and the result of the matches are consistent with the given information:

  • In the first match, contestants 44 and 55 played against each other, and contestant 44 won.
  • In the second match, contestants 22 and 44 played against each other, and contestant 22 won.
  • In the third match, contestants 11 and 33 played against each other, and contestant 11 won.
  • In the fourth match, contestants 11 and 22 played against each other, and contestant 11 won.

783f7be9c88350e31963edba8a958879.png

The depth of this tournament is 33, since contestant 55 must play three matches in order to win the championship. There is no tournament with depth 22 or less that is consistent with the given information, thus the output should be 33.

7
1
2
1
3
1
4
3
4
4
4
1
3