#include <bits/stdc++.h>
using namespace std;
void Freopen() {
  freopen(
      "title"
      ".in",
      "r", stdin);
  freopen(
      "title"
      ".out",
      "w", stdout);
}
int read() {
  int g = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    g = g * 10 + ch - '0';
    ch = getchar();
  }
  return g * f;
}
const int N = 3e5 + 5;
int n, a[N], b[N], id[N];
struct Seg {
  int mx[N << 2], tag[N << 2];
  void up(int v) { mx[v] = max(mx[v << 1], mx[v << 1 | 1]); }
  void updata(int v, int w) {
    tag[v] += w;
    mx[v] += w;
  }
  void down(int v) {
    if (tag[v]) updata(v << 1, tag[v]), updata(v << 1 | 1, tag[v]), tag[v] = 0;
  }
  void insert(int v, int l, int r, int ql, int qr, int w) {
    if (ql <= l && r <= qr) return updata(v, w), void();
    int mid = l + r >> 1;
    down(v);
    if (ql <= mid) insert(v << 1, l, mid, ql, qr, w);
    if (qr > mid) insert(v << 1 | 1, mid + 1, r, ql, qr, w);
    up(v);
  }
} seg;
signed main() {
  n = read();
  for (int i = (1); i <= (n); i++) a[i] = read(), id[a[i]] = i;
  for (int i = (1); i <= (n); i++) b[i] = read();
  seg.insert(1, 1, n, 1, id[n], 1);
  cout << n << ' ';
  int ans = n;
  for (int i = (1); i <= (n - 1); i++) {
    seg.insert(1, 1, n, 1, b[i], -1);
    while (seg.mx[1] <= 0) ans--, seg.insert(1, 1, n, 1, id[ans], 1);
    cout << ans << ' ';
  }
  return signed();
}
