#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 9;
int n, p[MAX], idx[MAX], tree[(MAX << 2)], lazy[(MAX << 2)];
int l, r, delta, ans;
void push(int low, int high, int pos) {
  tree[pos] += lazy[pos];
  if (low != high) {
    lazy[(pos << 1)] += lazy[pos];
    lazy[(pos << 1 | 1)] += lazy[pos];
  }
  lazy[pos] = 0;
}
void upd(int low, int high, int pos) {
  push(low, high, pos);
  if (l > high || r < low) {
    return;
  }
  if (l <= low && r >= high) {
    tree[pos] += delta;
    if (low != high) {
      lazy[(pos << 1)] += delta;
      lazy[(pos << 1 | 1)] += delta;
    }
    return;
  }
  int mid = ((low + high) >> 1);
  upd(low, mid, (pos << 1));
  upd(mid + 1, high, (pos << 1 | 1));
  tree[pos] = min(tree[(pos << 1)], tree[(pos << 1 | 1)]);
}
void check() {
  while (tree[1] >= 0) {
    --ans;
    l = 1;
    r = idx[ans];
    delta = -1;
    upd(1, n, 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    idx[p[i]] = i;
  }
  ans = n + 1;
  for (int i = 1; i <= n; ++i) {
    check();
    cout << ans << " ";
    int q;
    cin >> q;
    l = 1;
    r = q;
    delta = 1;
    upd(1, n, 1);
  }
  return 0;
}
