n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) posA = [0] * (n + 1) for i in range(n): x = a[i] posA[x] = i + 1 # 1-based posB = [0] * (n + 1) for i in range(n): x = b[i] posB[x] = i + 1 # 1-based sorted_teams = sorted(range(1, n + 1), key=lambda x: posA[x]) # Compute min_suffix min_suffix = [0] * n min_suffix[-1] = posB[sorted_teams[-1]] for i in range(n - 2, -1, -1): min_suffix[i] = min(posB[sorted_teams[i]], min_suffix[i + 1]) result = [] for x in range(1, n + 1): i = posA[x] - 1 # Convert to 0-based index in sorted_teams if i + 1 >= n: result.append(x) else: if posB[x] < min_suffix[i + 1]: result.append(x) for num in sorted(result): print(num)