#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 300010;
int t[N << 2], a[N], p[N], q[N], tag[N << 2], n;
void pushup(int o) { t[o] = max(t[o << 1], t[o << 1 | 1]); }
void puttag(int o, int k) {
  t[o] += k;
  tag[o] += k;
}
void pushdown(int o) {
  if (!tag[o]) return;
  puttag(o << 1, tag[o]);
  puttag(o << 1 | 1, tag[o]);
  tag[o] = 0;
}
void modify(int o, int l, int r, int posl, int posr, int k) {
  if (posl > posr) return;
  if (posl <= l && r <= posr) {
    puttag(o, k);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(o);
  if (posl <= mid) modify(o << 1, l, mid, posl, posr, k);
  if (mid < posr) modify(o << 1 | 1, mid + 1, r, posl, posr, k);
  pushup(o);
}
int main() {
  n = gi();
  int mx = 0;
  for (int i = 1; i <= n; i++) p[i] = gi(), a[p[i]] = i;
  for (int i = 1; i <= n; i++) q[i] = gi();
  int ans = n;
  printf("%d ", ans);
  modify(1, 1, n, 1, a[n], 1);
  for (int i = 1; i < n; i++) {
    modify(1, 1, n, 1, q[i], -1);
    while (t[1] <= 0 && ans > 1) {
      ans--;
      modify(1, 1, n, 1, a[ans], 1);
    }
    printf("%d ", ans);
  }
  puts("");
  return 0;
}
