#include <bits/stdc++.h>
using namespace std;
mt19937 rng(static_cast<unsigned int>(
    chrono::steady_clock::now().time_since_epoch().count()));
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) {
  a = (a + b) % m;
  if (a < 0) a += m;
}
template <typename num_t>
inline void unsafe_add_mod(num_t& a, const long long& b, const int& m) {
  a += b;
  if (a < 0)
    a += m;
  else if (a >= m)
    a -= m;
}
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) {
  return a < b ? a = b, true : false;
}
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) {
  return a > b ? a = b, true : false;
}
template <typename num_t>
num_t gcd(const num_t& lhs, const num_t& rhs) {
  return !lhs ? rhs : gcd(rhs % lhs, lhs);
}
template <typename num_t>
num_t lcm(const num_t& lhs, const num_t& rhs) {
  return lhs / ::gcd(lhs, rhs) * rhs;
}
template <typename num_t>
num_t pw(num_t n, num_t k, const num_t& mod) {
  if (k == -1) k = mod - 2;
  num_t res = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) res = 1ll * res * n % mod;
    n = 1ll * n * n % mod;
  }
  return res % mod;
}
const int inf = 1e9 + 7;
const int mod = 998244353;
const long long ll_inf = (long long)inf * inf * 9 + 7;
const int maxn = 1000000 + 7;
template <typename num_t>
class SegmentTree {
 public:
  void init(int l, int r) {
    tree.resize((r - l + 1) << 1);
    node_index = 0;
    build_tree(tree[node_index++], l, r);
  }
  void update(int left_index, int right_index, const num_t& val) {
    update_(tree[0], left_index, right_index, val);
  }
  num_t get(int left_index, int right_index) {
    if (right_index < left_index) return 0;
    return get(tree[0], left_index, right_index).first;
  }

 private:
  struct node {
    static const num_t nil = 0;
    node *left_child, *right_child;
    int left_index, right_index;
    num_t sum_left, sum_right;
    inline void push_down(num_t updated_value) {
      if (updated_value > 0)
        sum_left = 1;
      else if (updated_value < 0)
        sum_right = 1;
      if (sum_left && sum_right) {
        sum_left = sum_right = 0;
      }
    }
    inline void merge_node() {
      const node &lhs = *left_child, &rhs = *right_child;
      sum_right = lhs.sum_right;
      sum_left = rhs.sum_left;
      if (lhs.sum_left >= rhs.sum_right)
        sum_left += lhs.sum_left - rhs.sum_right;
      else
        sum_right += rhs.sum_right - lhs.sum_left;
    }
    inline void lazy_update() {}
    inline void init_value(num_t v = 0) { sum_left = sum_right = 0; }
    inline void init(int left, int right, node* left_child_,
                     node* right_child_) {
      left_index = left;
      right_index = right;
      left_child = left_child_;
      right_child = right_child_;
    }
    int size() const { return right_index - left_index + 1; }
  };
  vector<node> tree;
  int node_index = 0;
  void build_tree(node& root, int left, int right) {
    if (left == right) {
      root.init(left, right, nullptr, nullptr);
      root.init_value(0);
      return;
    }
    int mid = (left + right) >> 1, lhs = node_index++, rhs = node_index++;
    build_tree(tree[lhs], left, mid);
    build_tree(tree[rhs], mid + 1, right);
    root.init(left, right, &tree[lhs], &tree[rhs]);
    root.init_value(0);
    root.merge_node();
  }
  void update_(node& root, int u, int v, const num_t& value) {
    if (u > root.right_index || v < root.left_index) return;
    if (u <= root.left_index && root.right_index <= v) {
      root.push_down(value);
    } else {
      root.lazy_update();
      update_(*root.left_child, u, v, value);
      update_(*root.right_child, u, v, value);
      root.merge_node();
    }
  }
  pair<int, int> get(node& root, int u, int v) {
    if (u <= root.left_index && root.right_index <= v)
      return {root.sum_left, root.sum_right};
    if (u > root.right_index || v < root.left_index) return {0, 0};
    root.lazy_update();
    auto lhs = get(*root.left_child, u, v);
    auto rhs = get(*root.right_child, u, v);
    int sum_left = rhs.second;
    int sum_right = lhs.first;
    if (lhs.second >= rhs.first)
      sum_left += lhs.second - rhs.first;
    else
      sum_right += rhs.first - lhs.second;
    return {sum_left, sum_right};
  }
};
SegmentTree<int> segment_tree;
void solve() {
  int n;
  cin >> n;
  vector<int> p(n), q(n), rev(n + 1);
  for (int i = (0), _b = (n); i < _b; ++i) {
    cin >> p[i];
    rev[p[i]] = i + 1;
  }
  for (int i = (0), _b = (n); i < _b; ++i) cin >> q[i];
  int res = n;
  cout << res << ' ';
  segment_tree.init(1, n);
  segment_tree.update(rev[n], rev[n], 1);
  for (int i = (0), _b = (n - 1); i < _b; ++i) {
    int u = q[i];
    segment_tree.update(u, u, -1);
    while (segment_tree.get(1, n) <= 0) {
      int pos = rev[--res];
      segment_tree.update(pos, pos, 1);
    }
    cout << res << ' ';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = 0;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
