#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int mod = 998244353;
int a[N], b[N], sum[N << 2], maxx[N << 2], ans, c[N];
void pushup(int rt) {
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  maxx[rt] = max(maxx[rt << 1 | 1], maxx[rt << 1] + sum[rt << 1 | 1]);
}
void update(int x, int l, int r, int val, int rt) {
  if (l == r) {
    sum[rt] += val;
    maxx[rt] += val;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, l, mid, val, rt << 1);
  else
    update(x, mid + 1, r, val, rt << 1 | 1);
  pushup(rt);
}
int main() {
  int n, m, i, j, k, num;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), c[a[i]] = i;
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  ans = n;
  update(c[n], 1, n, 1, 1);
  for (i = 1; i <= n; i++) {
    while (maxx[1] <= 0) {
      ans--;
      update(c[ans], 1, n, 1, 1);
    }
    printf("%d ", ans);
    update(b[i], 1, n, -1, 1);
  }
  puts("");
  return 0;
}
