#include <bits/stdc++.h>
using namespace std;
long long tag[1200005], mx[1200005], p[300005], a[300005], q[300005];
long long read() {
  long long A;
  bool K;
  char C;
  C = A = K = 0;
  while (C < '0' || C > '9') K |= C == '-', C = getchar();
  while (C > '/' && C < ':') A = (A << 3) + (A << 1) + (C ^ 48), C = getchar();
  return (K ? -A : A);
}
void update(long long pos, long long l, long long r, long long x, long long y,
            long long val) {
  if (r < x || l > y) return;
  if (x <= l && r <= y) {
    tag[pos] += val;
    mx[pos] += val;
    return;
  }
  if (tag[pos]) {
    tag[pos << 1] += tag[pos];
    tag[pos << 1 | 1] += tag[pos];
    mx[pos << 1] += tag[pos];
    mx[pos << 1 | 1] += tag[pos];
    tag[pos] = 0;
  }
  long long mid = (l + r) >> 1;
  update(pos << 1, l, mid, x, y, val),
      update(pos << 1 | 1, mid + 1, r, x, y, val);
  mx[pos] = (mx[pos << 1] > mx[pos << 1 | 1] ? mx[pos << 1] : mx[pos << 1 | 1]);
}
void write(long long X) {
  if (X < 0) putchar('-'), X = -X;
  if (X > 9) write(X / 10);
  putchar(X % 10 | 48);
}
signed main() {
  long long n, i, now;
  n = now = read();
  for (i = 1; i <= n; i++) p[i] = read(), a[p[i]] = i;
  for (i = 1; i <= n; i++) q[i] = read();
  write(n);
  putchar(' ');
  update(1, 1, n, 1, a[n], 1);
  for (i = 1; i <= n - 1; i++) {
    update(1, 1, n, 1, q[i], -1);
    while (mx[1] <= 0) update(1, 1, n, 1, a[--now], 1);
    write(now);
    putchar(' ');
  }
  return 0;
}
