#include <bits/stdc++.h>
using namespace std;
const int maxn = 1200005;
int n;
int p[maxn], q[maxn];
struct Node {
  int left, right;
  int maxa, lazy;
} a[maxn];
void pushup(int id) { a[id].maxa = max(a[id << 1].maxa, a[id << 1 | 1].maxa); }
void buildtree(int id, int l, int r) {
  a[id].left = l;
  a[id].right = r;
  a[id].lazy = 0;
  if (l == r) {
    a[id].maxa = 0;
    return;
  }
  int mid = (l + r) / 2;
  buildtree(id << 1, l, mid);
  buildtree(id << 1 | 1, mid + 1, r);
  pushup(id);
}
void markadd(int id, int c) {
  a[id].lazy += c;
  a[id].maxa += c;
}
void pushdown(int id) {
  if (a[id].lazy) {
    markadd(id << 1, a[id].lazy);
    markadd(id << 1 | 1, a[id].lazy);
    a[id].lazy = 0;
  }
}
void change(int id, int l, int r, int c) {
  if (a[id].left == l && a[id].right == r) {
    markadd(id, c);
    return;
  }
  pushdown(id);
  if (a[id << 1].right >= r)
    change(id << 1, l, r, c);
  else if (a[id << 1 | 1].left <= l)
    change(id << 1 | 1, l, r, c);
  else {
    change(id << 1, l, a[id << 1].right, c);
    change(id << 1 | 1, a[id << 1 | 1].left, r, c);
  }
  pushup(id);
}
int query(int id, int l, int r) {
  if (a[id].left == l && a[id].right == r) {
    return a[id].maxa;
  }
  pushdown(id);
  if (a[id << 1].right >= r)
    return query(id << 1, l, r);
  else if (a[id << 1 | 1].left <= l)
    return query(id << 1 | 1, l, r);
  else {
    return max(query(id << 1, l, a[id << 1].right),
               query(id << 1 | 1, a[id << 1 | 1].left, r));
  }
}
int bk[maxn], ind;
int main() {
  cin >> n;
  ind = n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    bk[p[i]] = i;
  }
  for (int i = 1; i <= n; i++) cin >> q[i];
  buildtree(1, 1, n);
  change(1, 1, bk[n], 1);
  cout << n << ' ';
  for (int i = 1; i <= n - 1; i++) {
    change(1, 1, q[i], -1);
    while (query(1, 1, n) <= 0) {
      ind--;
      change(1, 1, bk[ind], 1);
    }
    cout << ind << ' ';
  }
  cout << endl;
  return 0;
}
