#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n), b(n), ans; vector used(n + 1); for(auto &&v : a) cin >> v; for(auto &&v : b) cin >> v; int i = 0, j = 0; while(j < n){ while(i < n && a[i] != b[j]){ used[a[i]] = true; i++; } ans.emplace_back(b[j]); used[b[j]] = true; while(j < n && used[b[j]]) j++; } sort(ans.begin(), ans.end()); for(auto &&v : ans) cout << v << '\n'; }