n = gets.to_i s, t = 2.times.map{ gets.split.map(&:to_i) } w, l = 2.times.map{ Array.new(n+1) } s.each_with_index{|v,i| w[v] = i } t.inject(-1){|j,v| (l[v] = w[v] > j) ? w[v] : j } puts (1..n).select{|v| l[v]}