import sys readline = sys.stdin.readline N = int(input()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) rank = [0 for _ in range(N + 1)] for i, a in enumerate(A): rank[a] = i + 1 ans = [] max_rank = 0 for b in B: if rank[b] > max_rank: ans.append(b) max_rank = rank[b] [print(i) for i in sorted(ans)]