#include <bits/stdc++.h>
using namespace std;
const int N = 300050;
int p[N], q[N], n, pos[N], mx[N << 2], tg[N << 2];
void pd(int p) {
  mx[p * 2] += tg[p], mx[p * 2 + 1] += tg[p];
  tg[p * 2] += tg[p], tg[p * 2 + 1] += tg[p];
  tg[p] = 0;
}
void upd(int p, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    mx[p] += v;
    tg[p] += v;
    return;
  }
  int mid = (l + r) >> 1;
  if (tg[p]) pd(p);
  if (L <= mid) upd(p * 2, l, mid, L, R, v);
  if (R > mid) upd(p * 2 + 1, mid + 1, r, L, R, v);
  mx[p] = max(mx[p * 2], mx[p * 2 + 1]);
}
bool dec(int t) {
  upd(1, 1, n, 1, pos[t], 1);
  if (mx[1] <= 0)
    return (1);
  else {
    upd(1, 1, n, 1, pos[t], -1);
    return (0);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]), pos[p[i]] = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i]);
  int answer = n;
  for (int i = 1; i <= n; ++i) {
    while (dec(answer)) --answer;
    printf("%d ", answer);
    upd(1, 1, n, 1, q[i], -1);
  }
  return (0);
}
