def main(): N = int(input()) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) award = [] apnd = award.append a = list(A) for i, j in enumerate(B): k = A.index(j) if i <= k and j in a: apnd(j) a[i:k] = [-1] * (k - i) for i in sorted(award): print(i) main()