#include <bits/stdc++.h>
using namespace std;
int n, p[300010], q[300010], pos[300010];
class sgt {
 public:
  int tag[1200010], mx[1200010];
  void pushnow(int p, int v) {
    tag[p] += v;
    mx[p] += v;
  }
  void pushdown(int p) {
    if (tag[p]) {
      pushnow((p << 1), tag[p]);
      pushnow(((p << 1) | 1), tag[p]);
      tag[p] = 0;
    }
  }
  void modify(int p, int l, int r, int ml, int mr, int v) {
    if (ml <= l && r <= mr) {
      pushnow(p, v);
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);
    if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);
    mx[p] = max(mx[(p << 1)], mx[((p << 1) | 1)]);
  }
} T;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]), pos[p[i]] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &q[i]);
  int curans = n;
  printf("%d ", curans);
  T.modify(1, 1, n, 1, pos[n], 1);
  for (int i = 1; i < n; i++) {
    T.modify(1, 1, n, 1, q[i], -1);
    while (T.mx[1] <= 0) {
      curans--;
      T.modify(1, 1, n, 1, pos[curans], 1);
    }
    printf("%d ", curans);
  }
  return 0;
}
