#include <bits/stdc++.h>
#pragma GCC optimizer(2)
using namespace std;
const int MAXN = 300005;
const int INF = 0x3f3f3f3f;
const int N = 300005;
const long long mod = 998244353;
priority_queue<int, vector<int>, less<int> > pq;
stack<int> st;
int pos[MAXN], val[MAXN << 2], lazy[MAXN << 2];
void pushdown(int rt) {
  if (lazy[rt]) {
    val[rt << 1] += lazy[rt];
    lazy[rt << 1] += lazy[rt];
    val[rt << 1 | 1] += lazy[rt];
    lazy[rt << 1 | 1] += lazy[rt];
    lazy[rt] = 0;
  }
}
void update(int rt, int l, int r, int L, int R, int x) {
  if (L <= l && r <= R) {
    val[rt] += x;
    lazy[rt] += x;
    return;
  }
  pushdown(rt);
  int mid = (l + r) >> 1;
  if (R <= mid)
    update(rt << 1, l, mid, L, R, x);
  else if (L > mid)
    update(rt << 1 | 1, mid + 1, r, L, R, x);
  else {
    update(rt << 1, l, mid, L, R, x);
    update(rt << 1 | 1, mid + 1, r, L, R, x);
  }
  val[rt] = min(val[rt << 1], val[rt << 1 | 1]);
}
int n, a[MAXN], p[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  int ans = n + 1;
  for (int i = 1; i <= n; i++) {
    while (val[1] >= 0) {
      ans--;
      update(1, 1, n, 1, pos[ans], -1);
    }
    printf("%d ", ans);
    update(1, 1, n, 1, p[i], 1);
  }
  return 0;
}
