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
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
import heapq
from locale import resetlocale
from pickle import FALSE
import random
import math
from collections import Counter
import sys
 
#parse a single integer
mod = 10**9+7
def inp():
    return(int(sys.stdin.readline()))
#parse a list of integers
def inlt():
    return(list(map(int,sys.stdin.readline().split())))
#parse a string (can be modified to parse a list of characters)
def insr():
    s = sys.stdin.readline()[:-1]
    return(s)
#no idea what this does
def invr():
    return(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
class UF:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size
        
    def find(self, x):
        if self.parent[x] == x:
            return x
        return self.find(self.parent[x])
    
    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] > self.rank[py]:
            self.parent[py] = px
        elif self.rank[px] < self.rank[py]:
            self.parent[px] = py
        else:
            self.parent[px] = py
            self.rank[py] += 1

class BIT:
    def __init__(self, n):
        self.sums = [0] * (n+1)
    
    def update(self, i, delta):
        while i < len(self.sums):
            self.sums[i] += delta
            i += i & (-i)
    
    def query(self, i):
        res = 0
        while i > 0:
            res += self.sums[i]
            i -= i & (-i)
        return res

class NumArray:
    def __init__(self, nums):
        self.bit = BIT(len(nums))
        for i, num in enumerate(nums):
            self.bit.update(i+1, num)
        self.nums = [0] + nums

    def update(self, i, val):
        self.bit.update(i+1, val - self.nums[i+1])
        self.nums[i+1] = val

    def sumRange(self, i, j):
        return self.bit.query(j+1) - self.bit.query(i)

# z = inp()
mod = 998244353
for v in range(1):
    n = inp()

    manager = [-1] * n 
    children = defaultdict(list)
    for i in range(n):
        m = inp()
        children[m-1].append(i)
    print(children)
    res = 0
    dp = defaultdict(int)
    def dfs(node):
        if node in dp:
            return dp[node]
        tmp = 0

        for c in children[node]:
            tmp = max(tmp, dfs(c))
        dp[node] = tmp + 1
        return 1 + tmp 
    res = 0
    for i in range(n):
        res = max(res, dfs(i))

    print(res)
        

    
