# def g(b, ans):
# l = len(b)
# for i in range(l):
# if b[i][1] < 10:
# b[i][0] = b[i][1]
# elif b[i][1] >= 10 and b[i][1] < 100:
# b[i][0] = b[i][1] % 10
# elif b[i][1] >= 100 and b[i][1] < 1000:
# b[i][0] = (b[i][1] % 100 - b[i][1] % 10) // 10
# else:
# b[i][0] = 0
# b.sort()
# c = []
# for i in range(l - 1, -1, -1):
# if i != 0 and b[i][0] == b[i - 1][0]:
# c.append(b[i])
# else:
# if len(c) != 0:
# c.append(b[i])
# g1(c, ans)
# c = []
# if i == 0:
# return
# else:
# ans.append(b[i][1])
#
#
# def g1(c, ans):
# l = len(c)
# for i in range(l):
# if c[i][1] < 10:
# c[i][0] = c[i][1]
# elif c[i][1] >= 10 and c[i][1] < 100:
# c[i][0] = c[i][1] // 10
# elif c[i][1] >= 100 and c[i][1] < 1000:
# c[i][0] = c[i][1] % 10
# else:
# c[i][0] = 0
# c.sort()
# d = []
# for i in range(l - 1, -1, -1):
# if i != 0 and c[i][0] == c[i - 1][0]:
# d.append(c[i])
# else:
# if len(d) != 0:
# d.append(c[i])
# g2(d, ans)
# d = []
# if i == 0:
# return
# else:
# ans.append(c[i][1])
#
#
# def g2(d, ans):
# l = len(d)
# for i in range(l):
# if d[i][1] < 10:
# d[i][0] = d[i][1]
# elif d[i][1] >= 10 and d[i][1] < 100:
# d[i][0] = d[i][1] // 10
# elif d[i][1] >= 100 and d[i][1] < 1000:
# d[i][0] = d[i][1] // 100
# else:
# d[i][0] = 0
# d.sort()
# e = []
# for i in range(l - 1, -1, -1):
# if i != 0 and d[i][0] == d[i - 1][0]:
# e.append(d[i])
# else:
# if len(e) != 0:
# e.append(d[i])
# g3(e, ans)
# e = []
# if i == 0:
# return
# else:
# ans.append(d[i][1])
#
#
# def g3(e, ans):
# l = len(e)
# e.sort()
# for i in range(l):
# if i < l - 1:
# a1 = e[i + 1][1]
# a = 1
# while a1 > 0:
# a1 //= 10
# a *= 10
# b1 = e[i][1]
# b = 1
# while b1 > 0:
# b1 //= 10
# b *= 10
# # print(e[i][1], e[i+1][1], e[i][1] a + e[i + 1][1], e[i + 1][1] b + e[i][0])
# if e[i][1] a + e[i + 1][1] < e[i + 1][1] b + e[i][1]:
# t = e[i]
# e[i] = e[i + 1]
# e[i + 1] = t
# ans.append(e[i][1])
#
#
# def solution(numbers):
# answer = ''
# k = len(numbers)
# numbers1 = [0] * k
# for i in range(k):
# numbers1[i] = int(numbers[i])
# numbers1.sort()
# a = []
# for i in range(k):
# if numbers1[i] < 10:
# v = [numbers1[i], numbers1[i]]
# a.append(v)
# elif numbers1[i] < 100:
# v = [numbers1[i] // 10, numbers1[i]]
# a.append(v)
# elif numbers1[i] < 1000:
# v = [numbers1[i] // 100, numbers1[i]]
# a.append(v)
# else:
# v = [numbers1[i] // 1000, numbers1[i]]
# a.append(v)
# a.sort()
# # print(a)
# b = []
# ans = []
# for i in range(k - 1, -1, -1):
# if i != 0 and a[i][0] == a[i - 1][0]:
# b.append(a[i])
# else:
# if len(b) != 0:
# b.append(a[i])
# g(b, ans)
# b = []
# if i == 0:
# break
# else:
# ans.append(a[i][1])
# print(ans)
#
# for i in range(len(ans)):
# ans[i] = str(ans[i])
# if ans[0] == '0':
# answer = '0'
# else:
# answer = ''.join(ans)
# return answer
#
#
# na = list(input().split())
# print(solution(na))
# 979 97 978 818 81 817
# 979 978 97 818 817 81
# 97 979 978 81 818 817
# def solution(citations):
# answer = 0
# k = len(citations)
# ca = []
# for i in range(k):
# ca.append(citations[i])
# ca.sort(reverse=True)
#
# for i in range(k):
# if ca[i] > i:
# answer += 1
# else:
# break
# return answer
# def g(b, ans):
# l = len(b)
# for i in range(l):
# if b[i][1] < 10:
# b[i][0] = b[i][1]
# elif b[i][1] >= 10 and b[i][1] < 100:
# b[i][0] = b[i][1] % 10
# elif b[i][1] >= 100 and b[i][1] < 1000:
# b[i][0] = (b[i][1] % 100 - b[i][1] % 10) // 10
# else:
# b[i][0] = 0
# b.sort()
# c = []
# for i in range(l - 1, -1, -1):
# if i != 0 and b[i][0] == b[i - 1][0]:
# c.append(b[i])
# else:
# if len(c) != 0:
# c.append(b[i])
# g1(c, ans)
# c = []
# if i == 0:
# return
# else:
# ans.append(b[i][1])
#
#
# def g1(c, ans):
# l = len(c)
# for i in range(l):
# if c[i][1] < 10:
# c[i][0] = c[i][1]
# elif c[i][1] >= 10 and c[i][1] < 100:
# c[i][0] = c[i][1] // 10
# elif c[i][1] >= 100 and c[i][1] < 1000:
# c[i][0] = c[i][1] % 10
# else:
# c[i][0] = 0
# c.sort()
# d = []
# for i in range(l - 1, -1, -1):
# if i != 0 and c[i][0] == c[i - 1][0]:
# d.append(c[i][1])
# else:
# if len(d) != 0:
# d.append(c[i][1])
# g2(d, ans)
# d = []
# if i == 0:
# return
# else:
# ans.append(c[i][1])
#
#
# def g2(e, ans):
# l = len(e)
# e.sort()
# # print('e', e)
# for j in range(l):
# for i in range(l-1, -1, -1):
# if i > 0 and e[i] != e[i-1]:
# a1 = e[i - 1]
# a = 1
# while a1 > 0:
# a1 //= 10
# a *= 10
# b1 = e[i]
# b = 1
# while b1 > 0:
# b1 //= 10
# b *= 10
# # print(e[i], e[i-1], e[i] a + e[i-1], e[i-1] b + e[i])
# if e[i] a + e[i - 1] > e[i - 1] b + e[i]:
# t = e[i]
# e[i] = e[i - 1]
# e[i - 1] = t
# ans.append(e[j])
#
#
# def solution(numbers):
# answer = ''
# k = len(numbers)
# numbers1 = [0] * k
# for i in range(k):
# numbers1[i] = int(numbers[i])
# numbers1.sort()
# a = []
# for i in range(k):
# if numbers1[i] < 10:
# v = [numbers1[i], numbers1[i]]
# a.append(v)
# elif numbers1[i] < 100:
# v = [numbers1[i] // 10, numbers1[i]]
# a.append(v)
# elif numbers1[i] < 1000:
# v = [numbers1[i] // 100, numbers1[i]]
# a.append(v)
# else:
# v = [numbers1[i] // 1000, numbers1[i]]
# a.append(v)
# a.sort()
# # print(a)
# b = []
# ans = []
# for i in range(k - 1, -1, -1):
# if i != 0 and a[i][0] == a[i - 1][0]:
# b.append(a[i])
# else:
# if len(b) != 0:
# b.append(a[i])
# g(b, ans)
# b = []
# if i == 0:
# break
# else:
# ans.append(a[i][1])
# # print('ans', ans)
#
# for i in range(len(ans)):
# ans[i] = str(ans[i])
# if ans[0] == '0':
# answer = '0'
# else:
# answer = ''.join(ans)
# return answer
#
#
# na = list(input().split())
# print(solution(na))
def g(d, ar, n, a):
t = 0
q = []
for i in range(2, n + 1, 1):
if i == a:
continue
if ar[i] == 0 and d[i][a] == 1:
ar[i] = ar[a] + 1
q.append(i)
while len(q) > t:
w = q[t]
t += 1
for i in range(2, n + 1, 1):
if i == w:
continue
if ar[i] == 0 and d[i][w] == 1:
ar[i] = ar[w] + 1
q.append(i)
def solution(n, edge):
answer = 0
k = len(edge)
d = []
ar = [0] * (n+1)
for i in range(n+1):
v = [0] * (n+1)
d.append(v)
for i in range(k):
d[edge[i][0]][edge[i][1]] = 1
d[edge[i][1]][edge[i][0]] = 1
g(d, ar, n, 1)
print(ar)
answer = ar.count(max(ar))
return answer
n = int(input())
ven = []
for i in range(1):
v = list(map(int, input().split()))
# v = [1, i + 2]
ven.append(v)
print(solution(n, ven))
# def g(d, n, a):
# p = 0
# for i in range(1, n + 1, 1):
# if i == a:
# continue
# if d[i][a] == 1:
# p += 1
# else:
# break
# return p
# def solution(n, results):
# answer = 0
# k = len(results)
# d = []
# for i in range(n+1):
# v = [0] * (n+1)
# d.append(v)
# for i in range(k):
# d[results[i][0]][results[i][1]] = 1
# d[results[i][1]][results[i][0]] = 1
# for i in range(1, n + 1, 1):
# if g(d, n, i) == n - 1
# answer += 1
# return answer