#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b, long long m) {
  long long res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long n;
const long long maxN = 3e5 + 5;
long long p[maxN], q[maxN], idx[maxN], res[maxN], tree[4 * maxN],
    lazy[4 * maxN];
void push(long long v) {
  tree[v * 2] += lazy[v];
  lazy[v * 2] += lazy[v];
  tree[v * 2 + 1] += 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 addend) {
  if (l > r) return;
  if (l == tl && tr == r) {
    tree[v] += addend;
    lazy[v] += addend;
  } else {
    push(v);
    long long tm = (tl + tr) / 2;
    update(v * 2, tl, tm, l, min(r, tm), addend);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);
    tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
  }
}
long long query(long long v, long long tl, long long tr, long long l,
                long long r) {
  if (l > r) return -(long long)9e18;
  if (l <= tl && tr <= r) return tree[v];
  push(v);
  long long tm = (tl + tr) / 2;
  return max(query(v * 2, tl, tm, l, min(r, tm)),
             query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> p[i];
    idx[p[i]] = i;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> q[i];
  }
  res[1] = n;
  long long ans = n;
  update(1, 1, n, 1, idx[ans], 1);
  for (long long i = 2; i <= n; i++) {
    update(1, 1, n, 1, q[i - 1], -1);
    long long mx = query(1, 1, n, 1, n);
    while (mx <= 0 and ans >= 1) {
      ans--;
      update(1, 1, n, 1, idx[ans], 1);
      mx = query(1, 1, n, 1, n);
    }
    res[i] = ans;
  }
  for (long long i = 1; i <= n; i++) {
    cout << res[i] << " ";
  }
  return 0;
}
