#include <bits/stdc++.h>
using namespace std;
struct Tree1 {
  int tree[1200002];
  void update(int i, int l, int r, int idx, int val) {
    if (l == r) {
      tree[i] = val;
      return;
    }
    int m = (l + r) >> 1;
    if (idx <= m)
      update(i * 2, l, m, idx, val);
    else
      update(i * 2 + 1, m + 1, r, idx, val);
    tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
  }
  int rangeMax(int i, int l, int r, int s, int e) {
    if (r < s || e < l) return 0;
    if (s <= l && r <= e) return tree[i];
    int m = (l + r) >> 1;
    return max(rangeMax(i * 2, l, m, s, e),
               rangeMax(i * 2 + 1, m + 1, r, s, e));
  }
} tree1;
struct Tree2 {
  int tree[1200002], lazy[1200002];
  void propagate(int i, int l, int r) {
    tree[i] += lazy[i];
    if (l != r) lazy[i * 2] += lazy[i], lazy[i * 2 + 1] += lazy[i];
    lazy[i] = 0;
  }
  void update(int i, int l, int r, int s, int e, int val) {
    propagate(i, l, r);
    if (r < s || e < l) return;
    if (s <= l && r <= e) {
      lazy[i] += val;
      propagate(i, l, r);
      return;
    }
    int m = (l + r) >> 1;
    update(i * 2, l, m, s, e, val), update(i * 2 + 1, m + 1, r, s, e, val);
    tree[i] = min(tree[i * 2], tree[i * 2 + 1]);
  }
  int findZero(int i, int l, int r, int s) {
    propagate(i, l, r);
    if (tree[i] || r < s) return -1;
    if (l == r) return l;
    int m = (l + r) >> 1;
    int tmp = findZero(i * 2, l, m, s);
    if (tmp != -1) return tmp;
    return findZero(i * 2 + 1, m + 1, r, s);
  }
} tree2;
int n;
int a[300002];
int aIdx[300002];
int b[300002];
set<int> st;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), aIdx[a[i]] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) st.insert(i);
  for (int i = 1; i <= n; i++) tree1.update(1, 1, n, i, a[i]);
  printf("%d ", n);
  for (int i = 1; i < n; i++) {
    int tmp = tree2.findZero(1, 1, n, b[i]);
    int targ = tree1.rangeMax(1, 1, n, 1, tmp);
    st.erase(targ);
    tree1.update(1, 1, n, aIdx[targ], 0);
    tree2.update(1, 1, n, aIdx[targ], n, 1);
    tree2.update(1, 1, n, b[i], n, -1);
    printf("%d ", *st.rbegin());
  }
}
