n = int(input()) import sys sys.setrecursionlimit(100000) value = list(map(int , input().split(' '))) if len(value)==1: print(value[0]) sys.exit() father = list(map(int , input().split(' '))) map = [ [] for i in range(n+1)] for i in range(n): if father[i]!=0: #map[i+1].app...