#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i2 = pair<int, int>;
const int N = 3e5 + 9;
const int inf = 1e9 + 9;
int P[N], Q[N], rev[N], add[4 * N], tree[4 * N];
int n, dsize;
void push(int u, int lo, int hi) {
  if (add[u]) {
    tree[u] += add[u];
    if (lo != hi) {
      add[u << 1] += add[u];
      add[u << 1 | 1] += add[u];
    }
    add[u] = 0;
  }
}
void upd(int u, int lo, int hi, int a, int b, int v) {
  push(u, lo, hi);
  if (a > b) {
    return;
  } else if (a == lo && b == hi) {
    add[u] += v;
    push(u, lo, hi);
  } else {
    int mid = (lo + hi) >> 1;
    upd(u << 1, lo, mid, a, min(b, mid), v);
    upd(u << 1 | 1, mid + 1, hi, max(a, mid + 1), b, v);
    tree[u] = min(tree[u << 1], tree[u << 1 | 1]);
  }
}
int query(int u, int lo, int hi, int a, int b) {
  if (a > b) {
    return inf;
  } else if (a == lo && b == hi) {
    return tree[u];
  } else {
    int mid = (lo + hi) >> 1;
    int l = query(u << 1, lo, mid, a, min(b, mid));
    int r = query(u << 1 | 1, mid + 1, hi, max(a, mid + 1), b);
    return min(l, r);
  }
}
bool decrease(int x) {
  upd(1, 0, dsize - 1, 1, rev[x], -1);
  if (query(1, 0, dsize - 1, 1, n) < 0) {
    upd(1, 0, dsize - 1, 1, rev[x], 1);
    return false;
  } else {
    return true;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  dsize = 1;
  while (dsize <= n) {
    dsize <<= 1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> P[i];
    rev[P[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> Q[i];
  }
  int res = n;
  for (int i = 1; i <= n; i++) {
    while (decrease(res)) res--;
    cout << res << " ";
    upd(1, 0, dsize - 1, 1, Q[i], 1);
  }
  return 0;
}
