#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long mo = 998244353;
int n;
int p[maxn], q[maxn];
int c[maxn << 2], lz[maxn << 2];
void pu(int rt) { c[rt] = max(c[(rt << 1)], c[((rt << 1) | 1)]); }
void pd(int rt) {
  if (lz[rt]) {
    c[(rt << 1)] += lz[rt];
    c[((rt << 1) | 1)] += lz[rt];
    lz[(rt << 1)] += lz[rt];
    lz[((rt << 1) | 1)] += lz[rt];
    lz[rt] = 0;
  }
}
void update(int rt, int l, int r, int L, int R, int x) {
  if (L <= l && r <= R) {
    c[rt] += x;
    lz[rt] += x;
    return;
  }
  pd(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) update((rt << 1), l, mid, L, R, x);
  if (R > mid) update(((rt << 1) | 1), mid + 1, r, L, R, x);
  pu(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return c[rt];
  pd(rt);
  int mid = (l + r) >> 1;
  int ans = -1;
  if (L <= mid) ans = max(ans, query((rt << 1), l, mid, L, R));
  if (R > mid) ans = max(ans, query(((rt << 1) | 1), mid + 1, r, L, R));
  return ans;
}
int main() {
  scanf("%d", &n);
  for (register int i = (1); i <= (n); i++) {
    int x;
    scanf("%d", &x);
    p[x] = i;
  }
  for (register int i = (1); i <= (n); i++) scanf("%d", &q[i]);
  int k = n;
  update(1, 1, n, 1, p[k], 1);
  for (register int i = (1); i <= (n); i++) {
    printf("%d%c", k, i == n ? '\n' : ' ');
    if (i == n) break;
    update(1, 1, n, 1, q[i], -1);
    while (query(1, 1, n, 1, n) <= 0) {
      update(1, 1, n, 1, p[--k], 1);
    }
  }
  return 0;
}
