n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p = {v: i for i, v in enumerate(b)} m = len(b) r = [] for i in a[::-1]: if p[i] < m: m = p[i] r.append(i) for i in sorted(r): print(i)