#include <bits/stdc++.h>
int n, p[1000005], id[1000005], q[1000005], ans[1000005];
int read() {
  char c = getchar();
  int ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans;
}
void Write(int x) {
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
struct node {
  int pre_min, sum, last;
  node operator+(const node b) const {
    int s = min(last, -b.pre_min);
    return (node){min(pre_min, sum + b.pre_min), sum + b.sum,
                  max(0, last - s + b.sum - b.pre_min)};
  }
} tree[1000005 << 2];
void build_tree(int L, int R, int rt) {
  tree[rt].pre_min = tree[rt].sum = tree[rt].last = 0;
  if (L == R) return;
  int mid = (L + R) >> 1;
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
  return;
}
void Insert(int L, int R, int x, int rt, int y) {
  if (L == R) {
    tree[rt].sum += y;
    tree[rt].pre_min = min(tree[rt].sum, 0);
    tree[rt].last = max(tree[rt].sum, 0);
    return;
  }
  int mid = (L + R) >> 1;
  if (mid >= x)
    Insert(L, mid, x, rt << 1, y);
  else
    Insert(mid + 1, R, x, rt << 1 | 1, y);
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
  return;
}
int main() {
  n = read();
  for (register int i = 1; i <= n; i++) id[p[i] = read()] = i;
  build_tree(1, n, 1);
  ans[0] = n + 1;
  for (register int i = 1; i <= n; i++) q[i] = read();
  for (register int i = 1; i <= n; i++) {
    ans[i] = ans[i - 1];
    while (!tree[1].last) Insert(1, n, id[--ans[i]], 1, 1);
    Write(ans[i]), putchar(' ');
    Insert(1, n, q[i], 1, -1);
  }
  return 0;
}
