#include <bits/stdc++.h>
using namespace std;
struct node {
  long long val, laze;
  node() { val = laze = 0; }
};
long long pos[302006];
long long a[302006];
node tree[4 * 302006];
long long bomb[302006];
void push_down(long long pos, long long l, long long r) {
  if (tree[pos].laze != 0) {
    tree[pos << 1].laze += tree[pos].laze;
    tree[pos << 1].val += tree[pos].laze;
    tree[pos << 1 | 1].laze += tree[pos].laze;
    tree[pos << 1 | 1].val += tree[pos].laze;
    tree[pos].laze = 0;
  }
}
void push_up(long long pos, long long l, long long r) {
  tree[pos].val = max(tree[pos << 1].val, tree[pos << 1 | 1].val);
}
void update(long long pos, long long l, long long r, long long L, long long R,
            long long val) {
  if (L <= l && R >= r) {
    tree[pos].laze += val;
    tree[pos].val += val;
    return;
  }
  push_down(pos, l, r);
  long long mid = (l + r) >> 1;
  if (L <= mid) update(pos << 1, l, mid, L, R, val);
  if (mid < R) update(pos << 1 | 1, mid + 1, r, L, R, val);
  push_up(pos, l, r);
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (long long i = 1; i <= n; i++) cin >> bomb[i];
  long long ans = n;
  update(1, 1, n, 1, pos[n], 1);
  for (long long i = 1; i <= n; i++) {
    while (tree[1].val <= 0) {
      ans--;
      update(1, 1, n, 1, pos[ans], 1);
    }
    cout << ans << " ";
    update(1, 1, n, 1, bomb[i], -1);
  }
}
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
