atcoder#ABC263B. [ABC263B] Ancestor

[ABC263B] Ancestor

Score : 200200 points

Problem Statement

There are NN people, called Person 11, Person 22, \ldots, Person NN.

The parent of Person ii (2iN)(2 \le i \le N) is Person PiP_i. Here, it is guaranteed that Pi<iP_i < i.

How many generations away from Person NN is Person 11?

Constraints

  • 2N502 \le N \le 50
  • 1Pi<i(2iN)1 \le P_i < i(2 \le i \le N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

P2P_2 P3P_3 \dots PNP_N

Output

Print the answer as a positive integer.

3
1 2
2

Person 22 is a parent of Person 33, and thus is one generation away from Person 33.

Person 11 is a parent of Person 22, and thus is two generations away from Person 33.

Therefore, the answer is 22.

10
1 2 3 4 5 6 7 8 9
9