#include <bits/stdc++.h>
using namespace std;
const int mxn = 3e5 + 5;
int lz[mxn * 4], st[mxn * 4];
int n, rev[mxn], q[mxn];
void push(int nw) {
  if (lz[nw] != 0) {
    lz[nw * 2] += lz[nw];
    st[nw * 2] += lz[nw];
    lz[nw * 2 + 1] += lz[nw];
    st[nw * 2 + 1] += lz[nw];
    lz[nw] = 0;
  }
}
void upd(int nw, int l, int r, int cl, int cr, int val) {
  if (r <= cl || cr <= l) return;
  if (l <= cl && cr <= r) {
    lz[nw] += val;
    st[nw] += val;
    return;
  }
  int md = (cl + cr) / 2;
  push(nw);
  upd(nw * 2, l, r, cl, md, val);
  upd(nw * 2 + 1, l, r, md, cr, val);
  st[nw] = min(st[nw * 2], st[nw * 2 + 1]);
}
bool dec(int x) {
  upd(1, 0, rev[x] + 1, 0, n, -1);
  if (st[1] >= 0) return true;
  upd(1, 0, rev[x] + 1, 0, n, 1);
  return false;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    rev[p] = i;
  }
  for (int i = 0; i < n; i++) cin >> q[i];
  int ans = n;
  for (int i = 0; i < n; i++) {
    while (dec(ans)) ans--;
    cout << ans << " ";
    upd(1, 0, q[i], 0, n, 1);
  }
}
