#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int N = 312345;
int st[4 * N], lz[4 * N], n;
const int inf = 1e9 + 7;
void push(int tl, int tr, int id) {
  st[id * 2] += lz[id];
  lz[id * 2] += lz[id];
  st[id * 2 + 1] += lz[id];
  lz[id * 2 + 1] += lz[id];
  lz[id] = 0;
}
int qmin(int l, int r, int tl = 0, int tr = n, int id = 1) {
  if (r < tl or l > tr) return inf;
  if (l <= tl and r >= tr) {
    return st[id];
  } else {
    push(tl, tr, id);
    int tm = (tl + tr) >> 1;
    return min(qmin(l, r, tl, tm, id * 2), qmin(l, r, tm + 1, tr, id * 2 + 1));
  }
}
void add(int l, int r, int x, int tl = 0, int tr = n, int id = 1) {
  if (r < tl or l > tr) return;
  if (l <= tl and r >= tr) {
    st[id] += x;
    lz[id] += x;
  } else {
    push(tl, tr, id);
    int tm = (tl + tr) >> 1;
    add(l, r, x, tl, tm, id * 2);
    add(l, r, x, tm + 1, tr, id * 2 + 1);
    st[id] = min(st[id * 2], st[id * 2 + 1]);
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  for (int i = (0); i < (4 * N); ++i) st[i] = lz[i] = 0;
  cin >> n;
  vector<long long> p(n + 1), pinv(n + 1), q(n + 1);
  for (int i = (1); i < (n + 1); ++i) {
    cin >> p[i];
    pinv[p[i]] = i;
  }
  for (int i = (1); i < (n + 1); ++i) cin >> q[i];
  int mx = n;
  add(1, pinv[n], -1);
  auto dec = [&]() {
    if (qmin(1, n) >= 0) {
      --mx;
      add(1, pinv[mx], -1);
      return true;
    } else {
      return false;
    }
  };
  for (int i = (1); i < (n + 1); ++i) {
    while (dec())
      ;
    cout << mx << ' ';
    add(1, q[i], 1);
  }
  cout << endl;
}
