#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 3;
int n, p[maxn], q[maxn];
void read() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) cin >> q[i];
}
int tr[maxn * 4], lazy[maxn * 4];
void merge(int v) { tr[v] = min(tr[v * 2], tr[v * 2 + 1]); }
void push(int v, int l, int r) {
  tr[v] += lazy[v];
  if (l != r) lazy[v * 2] += lazy[v], lazy[v * 2 + 1] += lazy[v];
  lazy[v] = 0;
}
void update(int v, int l, int r, int ll, int rr, int val) {
  push(v, l, r);
  if (l > rr || r < ll) return;
  if (l >= ll && r <= rr) {
    lazy[v] += val;
    push(v, l, r);
    return;
  }
  int mid = (l + r) / 2;
  update(v * 2, l, mid, ll, rr, val);
  update(v * 2 + 1, mid + 1, r, ll, rr, val);
  merge(v);
}
int pos[maxn];
void solve() {
  for (int i = 1; i <= n; i++) pos[p[i]] = i;
  int ans = n;
  for (int i = 1; i <= n; i++) {
    cout << min(n, ans + 1) << " ";
    update(1, 1, n, 1, q[i], 1);
    while (ans > 0 && tr[1] >= 0) {
      update(1, 1, n, 1, pos[ans], -1);
      ans--;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
