# 내 풀이
def dfs(now):
global ans
if K == now:
return
if not tree[now]:
ans += 1
return
for nxt in tree[now]:
dfs(nxt)
N = int(input())
lst = list(map(int, input().split()))
tree = [[] for _ in range(N+1)]
K = int(input())
start = 0
for i, v in enumerate(lst):
if v == -1:
start = i
elif i != K:
tree[v].append(i)
ans = 0
dfs(start)
print(ans)
# 다른 사람 풀이
def dfs(now):
lst[now] = -2
for i in range(N):
if lst[i] == now:
dfs(i)
N = int(input())
lst = list(map(int, input().split()))
tree = [[] for _ in range(N+1)]
K = int(input())
dfs(K)
ans = 0
for i in range(N):
if lst[i] != -2 and i not in lst:
ans += 1
print(ans)