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