#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
void print(T x, long long suc = 1) {
  cout << x;
  if (suc == 1)
    cout << '\n';
  else
    cout << ' ';
}
template <class T>
void print(const vector<T>& v, long long suc = 1) {
  for (long long i = 0; i < v.size(); i++)
    print(v[i], i == (long long)(v.size()) - 1 ? suc : 2);
}
const long long maxn = 1e6 + 7;
const long long mod = 998244353;
long long p[maxn], q[maxn];
long long pos[maxn];
long long a[maxn];
struct SegmentTree {
  long long mn[maxn << 2], mx[maxn << 2], sum[maxn << 2], add[maxn << 2],
      set[maxn << 2], L[maxn << 2], R[maxn << 2];
  void maketag_set(long long o, long long v) {
    add[o] = 0;
    set[o] = v;
    mx[o] = mn[o] = v;
    sum[o] = (R[o] - L[o] + 1) * v;
  }
  void maketag_add(long long o, long long v) {
    add[o] += v;
    mx[o] += v, mn[o] += v;
    sum[o] += (R[o] - L[o] + 1) * v;
  }
  void pushdown(long long o) {
    if (L[o] == R[o]) return;
    if (~set[o]) {
      maketag_set(o << 1, set[o]);
      maketag_set(o << 1 | 1, set[o]);
      set[o] = -1;
    }
    if (add[o]) {
      maketag_add(o << 1, add[o]);
      maketag_add(o << 1 | 1, add[o]);
      add[o] = 0;
    }
  }
  void pushup(long long o) {
    mx[o] = max(mx[o << 1], mx[o << 1 | 1]);
    mn[o] = min(mn[o << 1], mn[o << 1 | 1]);
    sum[o] = sum[o << 1] + sum[o << 1 | 1];
  }
  void build(long long o, long long l, long long r, long long* array = NULL) {
    long long mid(l + r >> 1);
    L[o] = l, R[o] = r;
    add[o] = 0;
    set[o] = -1;
    if (l == r) {
      if (array)
        mn[o] = mx[o] = sum[o] = array[l];
      else
        mn[o] = mx[o] = sum[o] = 0;
      return;
    }
    build(o << 1, l, mid, array);
    build(o << 1 | 1, mid + 1, r, array);
    pushup(o);
  }
  void Set(long long o, long long l, long long r, long long v) {
    long long mid(L[o] + R[o] >> 1);
    if (l <= L[o] and r >= R[o]) {
      maketag_set(o, v);
      return;
    }
    pushdown(o);
    if (l <= mid) Set(o << 1, l, r, v);
    if (r > mid) Set(o << 1 | 1, l, r, v);
    pushup(o);
  }
  void Add(long long o, long long l, long long r, long long v) {
    long long mid(L[o] + R[o] >> 1);
    if (l <= L[o] and r >= R[o]) {
      maketag_add(o, v);
      return;
    }
    pushdown(o);
    if (l <= mid) Add(o << 1, l, r, v);
    if (r > mid) Add(o << 1 | 1, l, r, v);
    pushup(o);
  }
  long long Sum(long long o, long long l, long long r) {
    pushdown(o);
    long long mid(L[o] + R[o] >> 1), ans(0);
    if (l <= L[o] and r >= R[o]) return sum[o];
    if (l <= mid) ans += Sum(o << 1, l, r);
    if (r > mid) ans += Sum(o << 1 | 1, l, r);
    return ans;
  }
  long long Min(long long o, long long l, long long r) {
    long long mid(L[o] + R[o] >> 1), ans((1ll << 60));
    if (l <= L[o] and r >= R[o]) return mn[o];
    pushdown(o);
    if (l <= mid) ans = min(ans, Min(o << 1, l, r));
    if (r > mid) ans = min(ans, Min(o << 1 | 1, l, r));
    return ans;
  }
  long long Max(long long o, long long l, long long r) {
    long long mid(L[o] + R[o] >> 1), ans(-(1ll << 60));
    if (l <= L[o] and r >= R[o]) return mx[o];
    pushdown(o);
    if (l <= mid) ans = max(ans, Max(o << 1, l, r));
    if (r > mid) ans = max(ans, Max(o << 1 | 1, l, r));
    return ans;
  }
} seg;
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> p[i], pos[p[i]] = i;
  for (long long i = 1; i <= n; ++i) cin >> q[i];
  seg.build(1, 1, n);
  long long now = n;
  seg.Add(1, 1, pos[now], 1);
  cout << n << " ";
  for (long long i = 1; i <= n - 1; ++i) {
    seg.Add(1, 1, q[i], -1);
    while (seg.Max(1, 1, n) <= 0 && now) {
      now--;
      seg.Add(1, 1, pos[now], 1);
    }
    cout << now << " ";
  }
}
