#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) # %% start_rank = {x: i for i, x in enumerate(A)} max_start_rank = -1 answer = [] for b in B: rank = start_rank[b] if rank > max_start_rank: answer.append(b) max_start_rank = rank # %% answer.sort() print('\n'.join(map(str, answer)))