#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
template <class T, class U>
void chmax(T& x, U y) {
  if (x < y) x = y;
}
template <class T, class U>
void chmin(T& x, U y) {
  if (y < x) x = y;
}
template <class T>
void mkuni(V<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
struct starryskytree {
  int N;
  using D = int;
  D id_ = -1e8;
  D id = -1e9;
  vector<D> mx, ad;
  starryskytree(vector<D> vc) {
    int n = vc.size();
    N = 1;
    while (N < n) N *= 2;
    mx.assign(N * 2, id_);
    ad.assign(N * 2, 0);
    for (int i = 0; i < int(n); i++) mx[i + N] = vc[i];
    for (int i = N - 1; i > 0; i--) mx[i] = max(mx[i * 2], mx[i * 2 + 1]);
  }
  void add(int a, int b, D v) { add(a, b, 0, N, 1, v); }
  void add(int a, int b, int l, int r, int k, D v) {
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      ad[k] += v;
      return;
    }
    add(a, b, l, (l + r) / 2, k * 2, v);
    add(a, b, (l + r) / 2, r, k * 2 + 1, v);
    mx[k] = max(mx[k * 2] + ad[k * 2], mx[k * 2 + 1] + ad[k * 2 + 1]);
  }
  D getmax(int a, int b) { return getmax(a, b, 0, N, 1); }
  D getmax(int a, int b, int l, int r, int k) {
    if (b <= l || r <= a) return id;
    if (a <= l && r <= b) return mx[k] + ad[k];
    return ad[k] + max(getmax(a, b, l, (l + r) / 2, k * 2),
                       getmax(a, b, (l + r) / 2, r, k * 2 + 1));
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  V<int> p(N), q(N);
  for (int i = 0; i < int(N); i++) cin >> p[i], p[i]--;
  for (int i = 0; i < int(N); i++) cin >> q[i], q[i]--;
  V<int> ip(N);
  for (int i = 0; i < int(N); i++) ip[p[i]] = i;
  int t = N - 1;
  starryskytree seg(V<int>(N, 0));
  for (int i = 0; i < int(N); i++) {
    void(0);
    while (seg.getmax(0, N) <= 0) {
      if (t < 0) assert(false);
      void(0);
      void(0);
      seg.add(0, ip[t] + 1, 1);
      t--;
    }
    cout << t + 2 << " ";
    seg.add(0, q[i] + 1, -1);
  }
  cout << endl;
}
