#include <bits/stdc++.h>
using namespace std;
long long n, a[300005], t[12000005], pos[300005], p, lazy[12000005];
void push(long long v) {
  if (lazy[v]) {
    t[v * 2] += lazy[v];
    t[v * 2 + 1] += lazy[v];
    lazy[v * 2] += lazy[v];
    lazy[v * 2 + 1] += lazy[v];
    lazy[v] = 0;
  }
}
void update(long long v, long long tl, long long tr, long long l, long long r,
            long long x) {
  if (tl > r || tr < l)
    return;
  else if (tl >= l && tr <= r) {
    t[v] += x;
    lazy[v] += x;
  } else {
    long long tm = (tl + tr) / 2;
    push(v);
    update(v * 2, tl, tm, l, r, x);
    update(v * 2 + 1, tm + 1, tr, l, r, x);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;
  long long ans = n;
  for (long long i = 1; i <= n; i++) {
    cin >> p;
    while (1) {
      update(1, 1, n, 1, pos[ans], -1);
      if (t[1] < 0) {
        update(1, 1, n, 1, pos[ans], 1);
        break;
      }
      ans--;
    }
    cout << ans << " ";
    update(1, 1, n, 1, p, 1);
  }
  return 0;
}
