#include <bits/stdc++.h>
using namespace std;
class Segment_Tree1 {
  int l, r;
  long long *mx, *mi, *sum, *tag;
  long long inf;
  void pushdown(int pos, int l, int r) {
    mx[(pos << 1)] += tag[pos];
    mx[(pos << 1 | 1)] += tag[pos];
    mi[(pos << 1)] += tag[pos];
    mi[(pos << 1 | 1)] += tag[pos];
    sum[(pos << 1)] += tag[pos] * (((l + r) >> 1) - l + 1);
    sum[(pos << 1 | 1)] += tag[pos] * (r - ((l + r) >> 1));
    tag[(pos << 1)] += tag[pos];
    tag[(pos << 1 | 1)] += tag[pos];
    tag[pos] = 0;
  }
  void pushup(int pos, int l, int r) {
    mi[pos] = min(mi[(pos << 1)], mi[(pos << 1 | 1)]) + tag[pos];
    mx[pos] = max(mx[(pos << 1)], mx[(pos << 1 | 1)]) + tag[pos];
    sum[pos] = sum[(pos << 1)] + sum[(pos << 1 | 1)] + tag[pos] * (r - l + 1);
  }
  void build(int pos, int l, int r, long long *a) {
    if (l == r) {
      mx[pos] = mi[pos] = sum[pos] = a[l];
      return;
    }
    build((pos << 1), l, ((l + r) >> 1), a);
    build((pos << 1 | 1), ((l + r) >> 1) + 1, r, a);
    pushup(pos, l, r);
  }
  void modify(int pos, int l, int r, int L, int R, long long k) {
    if (r < L || l > R) return;
    if (l >= L && r <= R) {
      tag[pos] += k;
      mx[pos] += k;
      mi[pos] += k;
      sum[pos] += k * (r - l + 1);
      return;
    }
    pushdown(pos, l, r);
    modify((pos << 1), l, ((l + r) >> 1), L, R, k);
    modify((pos << 1 | 1), ((l + r) >> 1) + 1, r, L, R, k);
    pushup(pos, l, r);
  }
  long long querymi(int pos, int l, int r, int L, int R) {
    if (r < L || l > R) return inf;
    if (l >= L && r <= R) return mi[pos];
    pushdown(pos, l, r);
    return min(querymi((pos << 1), l, ((l + r) >> 1), L, R),
               querymi((pos << 1 | 1), ((l + r) >> 1) + 1, r, L, R));
  }
  long long querymx(int pos, int l, int r, int L, int R) {
    if (r < L || l > R) return -inf;
    if (l >= L && r <= R) return mx[pos];
    pushdown(pos, l, r);
    return max(querymx((pos << 1), l, ((l + r) >> 1), L, R),
               querymx((pos << 1 | 1), ((l + r) >> 1) + 1, r, L, R));
  }
  long long querysum(int pos, int l, int r, int L, int R) {
    if (r < L || l > R) return 0;
    if (l >= L && r <= R) return sum[pos];
    pushdown(pos, l, r);
    return querysum((pos << 1), l, ((l + r) >> 1), L, R) +
           querysum((pos << 1 | 1), ((l + r) >> 1) + 1, r, L, R);
  }

 public:
  void Clear() {
    for (int i = 0; i < (r - l + 5) << 2; i++)
      mx[i] = mi[i] = sum[i] = tag[i] = 0;
  }
  Segment_Tree1(int _l = 0, int _r = 310000) {
    memset(&inf, 0x3f, sizeof(long long));
    l = _l;
    r = _r;
    mx = new long long[(r - l + 5) << 2];
    mi = new long long[(r - l + 5) << 2];
    sum = new long long[(r - l + 5) << 2];
    tag = new long long[(r - l + 5) << 2];
    Clear();
  }
  ~Segment_Tree1() {
    delete mx;
    delete mi;
    delete sum;
    delete tag;
  }
  void Build(long long *a) { build(1, l, r, a); }
  void Add(int L, int R, long long x) { modify(1, l, r, L, R, x); }
  long long Qmin(int L, int R) { return querymi(1, l, r, L, R); }
  long long Qmax(int L, int R) { return querymx(1, l, r, L, R); }
  long long Qsum(int L, int R) { return querysum(1, l, r, L, R); }
};
int n;
int p[310000];
int pos[310000];
int q[310000];
int ans;
int main() {
  cin >> n;
  Segment_Tree1 sgt(0, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    pos[p[i]] = i;
  }
  ans = n;
  cout << ans << ' ';
  sgt.Add(1, pos[n], 1);
  for (int i = 1; i < n; i++) {
    scanf("%d", &q[i]);
    sgt.Add(1, q[i], -1);
    while (sgt.Qmax(1, n) <= 0) {
      ans--;
      sgt.Add(1, pos[ans], 1);
    }
    printf("%d ", ans);
  }
  return 0;
}
