#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 55;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T, typename E>
class SegTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using W = function<E(E, ll)>;

 public:
  ll N;
  F f;
  G g;
  H h;
  W w;
  T ti;
  E ei;
  vector<T> data;
  vector<E> lazy;
  void eval(ll k, ll len) {
    if (lazy[k] == ei) return;
    if (k < N - 1) {
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      lazy[2 * k + 2] = h(lazy[2 * k + 2], lazy[k]);
    }
    data[k] = g(data[k], w(lazy[k], len));
    lazy[k] = ei;
  }
  void _update(ll a, ll b, E x, ll k, ll l, ll r) {
    eval(k, r - l);
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      eval(k, r - l);
    } else if (a < r && l < b) {
      _update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      _update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      data[k] = f(data[2 * k + 1], data[2 * k + 2]);
    }
  }
  T _query(ll a, ll b, ll k, ll l, ll r) {
    eval(k, r - l);
    if (r <= a || b <= l) {
      return ti;
    } else if (a <= l && r <= b) {
      return data[k];
    } else {
      T left = _query(a, b, 2 * k + 1, l, (l + r) / 2);
      T right = _query(a, b, 2 * k + 2, (l + r) / 2, r);
      return f(left, right);
    }
  }
  SegTree(F f, G g, H h, W w, T ti, E ei)
      : f(f), g(g), h(h), w(w), ti(ti), ei(ei) {}
  void init(ll n) {
    N = 1;
    while (N < n) N *= 2;
    data.resize(2 * N - 1, ti);
    lazy.resize(2 * N - 1, ei);
  }
  void build(const vector<T> &v) {
    ll n = v.size();
    init(n);
    for (ll i = 0; i < n; i++) data[i + N - 1] = v[i];
    for (ll i = N - 2; i >= 0; i--) {
      data[i] = f(data[2 * i + 1], data[2 * i + 2]);
    }
  }
  void update(ll a, ll b, E x) { _update(a, b, x, 0, 0, N); }
  T query(ll a, ll b) { return _query(a, b, 0, 0, N); }
};
signed main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll N;
  cin >> N;
  vector<ll> P(N);
  vector<ll> pos(N + 1);
  vector<ll> Q(N);
  for (ll i = 0; i < N; i++) {
    cin >> P[i];
    pos[P[i]] = i;
  }
  for (ll i = 0; i < N; i++) {
    cin >> Q[i];
    Q[i]--;
  }
  ll X = N;
  using T = long long;
  using E = long long;
  auto f = [](T t1, T t2) -> T { return min(t1, t2); };
  auto g = [](T t, E e) -> T { return t + e; };
  auto h = [](E e1, E e2) -> E { return e1 + e2; };
  auto w = [](E e, ll len) -> E { return e; };
  T ti = INF;
  E ei = 0;
  auto seg = new SegTree<T, E>(f, g, h, w, ti, ei);
  vector<long long> first(N, 0);
  for (ll i = 0; i <= pos[N]; i++) first[i] = -1;
  seg->build(first);
  for (ll i = 0; i < N; i++) {
    cout << X << endl;
    ll b = Q[i];
    seg->update(0, b + 1, 1);
    while (seg->query(0, N) >= 0) {
      X--;
      seg->update(0, pos[X] + 1, -1);
    }
  }
  return 0;
}
