#include <bits/stdc++.h>
using namespace std;
inline void chkmax(long long &a, long long b) {
  if (a < b) a = b;
}
inline void chkmin(long long &a, long long b) {
  if (a > b) a = b;
}
inline long long read() {
  long long a = 0, fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a * fh;
}
long long T, n, m;
char ch[300005];
long long a[300005], b[300005];
long long Min[300005 << 2], tag[300005 << 2], loc[300005], p[300005];
void pd(long long x) {
  if (tag[x]) {
    Min[(x << 1)] += tag[x];
    Min[(x << 1 | 1)] += tag[x];
    tag[(x << 1)] += tag[x];
    tag[(x << 1 | 1)] += tag[x];
    tag[x] = 0;
  }
}
void cover(long long x, long long l, long long r, long long b, long long e,
           long long op) {
  if (l > e || r < b) return;
  if (b <= l && r <= e) {
    Min[x] += op;
    tag[x] += op;
    return;
  }
  pd(x);
  if (b <= ((l + r) >> 1)) cover((x << 1), l, ((l + r) >> 1), b, e, op);
  if (e > ((l + r) >> 1)) cover((x << 1 | 1), ((l + r) >> 1) + 1, r, b, e, op);
  Min[x] = max(Min[(x << 1)], Min[(x << 1 | 1)]);
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; ++i) {
    a[i] = read();
    loc[a[i]] = i;
  }
  long long mx = n;
  printf("%d ", mx);
  cover(1, 1, n, 1, loc[mx], 1);
  for (long long i = 1; i < n; ++i) {
    long long p = read();
    cover(1, 1, n, 1, p, -1);
    while (Min[1] <= 0 && mx) {
      mx--;
      cover(1, 1, n, 1, loc[mx], 1);
    }
    printf("%d ", mx);
  }
  return 0;
}
