#include <bits/stdc++.h>
const int maxn = 1e6 + 20;
const int maxm = 1e5 + 10;
const int mod = 998244353;
const long long int INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n;
int a[maxn], b[maxn], x;
int sum[maxn << 2], num[maxn << 2];
void update(int pos, int c, int l, int r, int rt) {
  if (l == r) {
    sum[rt] += c;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    update(pos, c, l, mid, rt << 1);
  else
    update(pos, c, mid + 1, r, rt << 1 | 1);
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  num[rt] = max(num[rt << 1] + sum[rt << 1 | 1], num[rt << 1 | 1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = 1; i <= n; i++) scanf("%d", b + i);
  update(a[n], 1, 1, n, 1);
  int now = n;
  for (int i = 1; i <= n; i++) {
    printf("%d%c", now, i == n ? '\n' : ' ');
    update(b[i], -1, 1, n, 1);
    while (max(sum[1], num[1]) == 0) {
      update(a[--now], 1, 1, n, 1);
    }
  }
}
