N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) DA, DB = [0] * N, [0] * N for i in range(N): DA[A[i] - 1] = i DB[B[i] - 1] = i D = [] for i in range(N): D.append((DA[i], DB[i], i + 1)) D.sort() ans = [] mi = 10 ** 18 for i in range(N - 1, -1, -1): if D[i][1] <= mi: ans.append(D[i][2]) mi = D[i][1] ans.sort() for a in ans: print(a)