N = int(input()) A = input() A = A.split(" ") A = [int(i) for i in A] B = input() B = B.split(" ") B = [int(i) for i in B] maxnum = [-1]*N c = [] for i in range(N): for j in range(i+1): if(maxnum[i] <= A.index(B[j])): maxnum[i] = A.index(B[j]) if(maxnum[i] == A.index(B[i])): c.append(B[i]) c.sort() for x in c: print(x)