#include <bits/stdc++.h>
using namespace std;
const int S = 1 << 19;
struct seg_node {
int sum;
int suff;
};
seg_node seg[2*S];
void update_node(int i) {
if (i >= S) {
seg[i].suff = max(0, seg[i].sum);
} else {
seg[i].sum = seg[2*i].sum + seg[2*i+1].sum;
seg[i].suff = max(seg[2*i+1].suff, seg[2*i+1].sum + seg[2*i].suff);
}
}
void update(int i, int d) {
seg[i+S].sum += d;
for (int a = i+S; a; a /= 2) {
update_node(a);
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int N; cin >> N;
vector<int> P(N);
vector<int> invP(N);
for (int i = 0; i < N; i++) {
cin >> P[i]; P[i] --;
invP[P[i]] = i;
}
int curAns = N;
for (int i = 0; i < N; i++) {
while (seg[1].suff <= 0) {
curAns--;
update(invP[curAns], 1);
}
cout << curAns+1 << " \n"[i+1==N];
int loc; cin >> loc; loc--;
update(loc, -1);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgUyA9IDEgPDwgMTk7CnN0cnVjdCBzZWdfbm9kZSB7CglpbnQgc3VtOwoJaW50IHN1ZmY7Cn07CnNlZ19ub2RlIHNlZ1syKlNdOwoKdm9pZCB1cGRhdGVfbm9kZShpbnQgaSkgewoJaWYgKGkgPj0gUykgewoJCXNlZ1tpXS5zdWZmID0gbWF4KDAsIHNlZ1tpXS5zdW0pOwoJfSBlbHNlIHsKCQlzZWdbaV0uc3VtID0gc2VnWzIqaV0uc3VtICsgc2VnWzIqaSsxXS5zdW07CgkJc2VnW2ldLnN1ZmYgPSBtYXgoc2VnWzIqaSsxXS5zdWZmLCBzZWdbMippKzFdLnN1bSArIHNlZ1syKmldLnN1ZmYpOwoJfQp9Cgp2b2lkIHVwZGF0ZShpbnQgaSwgaW50IGQpIHsKCXNlZ1tpK1NdLnN1bSArPSBkOwoJZm9yIChpbnQgYSA9IGkrUzsgYTsgYSAvPSAyKSB7CgkJdXB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