#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
struct data {
  int s, pmn, smx;
  data(int x = 0, int y = 0, int z = 0) : s(x), pmn(y), smx(z) {}
  inline data operator+(const data &p) const {
    return data(s + p.s, min(pmn, s + p.pmn), max(smx + p.s, p.smx));
  }
} tr[maxn << 2];
int n, a[maxn], pos[maxn];
inline void pushup(int rt) { tr[rt] = tr[rt << 1] + tr[(rt << 1) | 1]; }
void build(int rt, int l, int r) {
  tr[rt] = data();
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid), build((rt << 1) | 1, mid + 1, r);
}
data query(int rt, int l, int r, int x, int y) {
  if (x > y) return data();
  if (x <= l && r <= y) return tr[rt];
  int mid = (l + r) >> 1;
  data res = data();
  if (x <= mid) res = res + query(rt << 1, l, mid, x, y);
  if (mid < y) res = res + query((rt << 1) | 1, mid + 1, r, x, y);
  return res;
}
void update(int rt, int l, int r, int x, int z) {
  if (l == r) {
    tr[rt].s += z, tr[rt].pmn = min(0, tr[rt].s), tr[rt].smx = max(0, tr[rt].s);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(rt << 1, l, mid, x, z);
  else
    update((rt << 1) | 1, mid + 1, r, x, z);
  pushup(rt);
}
int main() {
  int i, k, x;
  scanf("%d", &n);
  build(1, 1, n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), pos[a[i]] = i;
  for (k = n, i = 1; i <= n; i++) {
    printf("%d ", k);
    if (i == n) break;
    scanf("%d", &x);
    update(1, 1, n, x, -1);
    for (;
         query(1, 1, n, pos[k], n).pmn + query(1, 1, n, 1, pos[k] - 1).smx < 0;
         k--)
      update(1, 1, n, pos[k], 1);
  }
  printf("\n");
  return 0;
}
