n = gets.to_i s = gets.split.map(&:to_i) t = gets.split.map(&:to_i) w = Array.new(n) s.each_with_index do |v,i| w[v] = i end ans = [] t.inject(-1) do |m,v| if w[v] > m ans << v w[v] else m end end puts ans.sort