#include <bits/stdc++.h>
using namespace std;
inline void INP();
const int N = 4e5 + 7, inf = INT_MAX;
int n, Q, arr[N + 2], p[N];
template <typename T>
class segment_tree {
 public:
  int sz, lz = 1;
  vector<T> segt;
  vector<int> lazy;
  void init(int x) {
    lz = 1;
    sz = x;
    segt.assign(4 * sz, 0);
    lazy.assign(4 * sz, 0);
  }
  T ff(T a, T b) { return max(a, b); }
  void push(int i, int l, int r) {
    segt[i] += lazy[i];
    if (l != r) {
      lazy[2 * i + 1] += lazy[i];
      lazy[2 * i + 2] += lazy[i];
    }
    lazy[i] = 0;
  }
  T qry(int l, int r, int i, int L, int R) {
    if (lazy[i] != 0 and lz) push(i, l, r);
    if (r < L or R < l) return -inf;
    if (L <= l and r <= R) return segt[i];
    int mid = (l + r) / 2;
    T a = qry(l, mid, 2 * i + 1, L, R), b = qry(mid + 1, r, 2 * i + 2, L, R);
    if (lz) get(i);
    return ff(a, b);
  }
  void upd(int l, int r, int i, int L, int R, int val) {
    if (lazy[i] != 0 and lz) push(i, l, r);
    if (l > R or L > r) return;
    if (L <= l and r <= R) {
      lazy[i] += val;
      push(i, l, r);
      return;
    }
    int mid = (l + r) / 2;
    upd(l, mid, i * 2 + 1, L, R, val);
    upd(mid + 1, r, i * 2 + 2, L, R, val);
    get(i);
  }
  T query(int L, int R = -1) {
    if (R == -1) R = L;
    return qry(1, sz - 1, 0, L, R);
  }
  void update(int val, int L, int R = -1) {
    if (R == -1) R = L;
    upd(1, sz - 1, 0, L, R, val);
  }
  void get(int i) { segt[i] = ff(segt[2 * i + 1], segt[2 * i + 2]); }
};
int idx[N];
void solve() {
  cin >> n;
  for (int i = 1; i < (int)n + 1; i++) cin >> arr[i], idx[arr[i]] = i;
  for (int i = 1; i < (int)n + 1; i++) cin >> p[i];
  segment_tree<int> sgt;
  sgt.init(n + 1);
  int ans = n, cnt = 0;
  sgt.update(1, 1, idx[n]);
  int res = sgt.query(1, n);
  for (int i = 1; i < (int)n + 1; i++) {
    int res = sgt.query(1, n);
    while (res <= 0) {
      ans--;
      sgt.update(1, 1, idx[ans]);
      res = sgt.query(1, n);
    }
    cout << ans << " ";
    sgt.update(-1, 1, p[i]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  INP();
  int test = 1;
  while (test--) solve();
}
inline void INP() {}
