#include using namespace std; typedef long long ll; typedef pair PII; const int MM = 1e9 + 7; const double eps = 1e-8; const int MAXN = 2e6 + 10; int n, m; void prework(){ } void read(){ } int a[MAXN], b[MAXN], f[MAXN]; void solve(int casi){ // cout << "Case #" << casi << ": "; cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = 1; i <= n; i++){ cin >> b[i]; f[b[i]] = i; } vector ans; int ear = n + 1; for (int i = n; i >= 1; i--){ if (f[a[i]] < ear) ans.push_back(a[i]); ear = min(ear, f[a[i]]); } sort(ans.begin(), ans.end()); for (auto &x : ans) cout << x << endl; } void printans(){ } int main(){ std::ios::sync_with_stdio(false); prework(); int T = 1; // cin>>T; for(int i = 1; i <= T; i++){ read(); solve(i); printans(); } return 0; }