A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
 -  Employee *A* is the immediate manager of employee *B* -  Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. 
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.

Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.

What is the minimum number of groups that must be formed?
The first line contains integer *n* (1 ≤ *n* ≤ 2000) — the number of employees.

The next *n* lines contain the integers *p*<sub class="lower-index">*i*</sub> (1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ *n* or *p*<sub class="lower-index">*i*</sub> = -1). Every *p*<sub class="lower-index">*i*</sub> denotes the immediate manager for the *i*-th employee. If *p*<sub class="lower-index">*i*</sub> is -1, that means that the *i*-th employee does not have an immediate manager. 

It is guaranteed, that no employee will be the immediate manager of him/herself (*p*<sub class="lower-index">*i*</sub> ≠ *i*). Also, there will be no managerial cycles.
5
-1
1
2
1
-1
3
4
-1
1
2
3
4
12
-1
1
2
3
-1
5
6
7
-1
9
10
11
4
6
-1
-1
2
3
1
1
3
3
-1
1
1
2
1
-1
1
2
2
-1
2
2
-1
-1
1
3
2
-1
1
3
3
-1
-1
-1
1
5
4
5
1
-1
4
3
12
-1
1
1
1
1
1
3
4
3
3
4
7
4
12
-1
-1
1
-1
1
1
5
11
8
6
6
4
5
12
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
2
12
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
12
3
4
2
8
7
1
10
12
5
-1
9
11
12
12
5
6
7
1
-1
9
12
4
8
-1
3
2
11
12
-1
9
11
6
6
-1
6
3
8
6
1
6
6
12
7
8
4
12
7
9
-1
-1
-1
8
6
-1
3
12
-1
10
-1
1
-1
5
9
12
-1
-1
3
-1
2
12
-1
7
9
12
1
7
-1
-1
8
5
4
-1
3
12
11
11
8
9
1
1
2
-1
10
3
-1
8
5
12
-1
8
9
-1
4
2
11
1
-1
6
-1
10
6
12
7
4
4
-1
6
7
9
7
-1
7
4
1
4
12
-1
6
10
6
1
11
5
9
11
5
1
9
4
12
8
6
6
8
6
-1
6
6
8
6
8
8
3
12
3
8
9
12
2
8
11
12
2
9
-1
11
7
7
7
6
-1
-1
4
4
-1
3
77
53
-1
48
-1
51
-1
54
43
70
19
64
31
45
58
6
61
41
56
34
-1
54
-1
66
65
74
16
38
1
2
61
-1
34
-1
-1
7
19
57
13
61
42
-1
34
65
16
31
61
6
5
34
15
-1
13
4
22
74
7
-1
70
38
61
45
53
46
22
-1
65
34
19
43
48
33
58
36
-1
47
24
34
6
5
2
3
4
5
-1
5
mx=0
a={-1:[]}
def dfs(x,y):
    global mx
    global a
    mx=max(mx,y)
    for i in x:
        dfs(a[i],y+1)
n=int(input())
for i in range(1,2001):
    a[i] = []
for i in range(1,n+1):
    x=int(input())
    a[x].append(i)
for i in a[-1]:
    dfs(a[i],1)
print(mx)







2000
1720
521
769
580
369
1830
584
1435
631
1717
1539
909
138
1786
962
128
561
1999
969
1082
216
1165
1758
683
11
1191
1285
210
637
498
1531
1891
1995
394
1905
308
98
172
955
1125
1288
618
1199
1589
1848
1688
435
1554
1171
1886
1500
379
572
674
137
1959
970
1625
1951
1909
1832
850
1201
537
362
662
1655
129
1271
1310
1424
1879
1092
1865
1192
1664
110
1080
1987
436
654
1095
1675
1419
158
48
1824
914
636
1831
450
1807

