#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("vpt")
#pragma GCC optimize("rename-registers")
#pragma GCC optimize("move-loop-invariants")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("branch-target-load-optimize2")
#pragma GCC optimize("btr-bb-exclusive")
using namespace std;
const int MAXN = 300001;
int pos[MAXN];
mt19937 rnd(8611731);
struct Node {
  int value, p, size, f, add;
  Node *left, *right;
  Node(int x)
      : value(x),
        p(rnd()),
        size(1),
        f(x),
        add(0),
        left(nullptr),
        right(nullptr) {}
}* root = nullptr;
void push(Node* root) {
  if (root && root->add) {
    root->value += root->add;
    root->f += root->add;
    if (root->left) root->left->add += root->add;
    if (root->right) root->right->add += root->add;
    root->add = 0;
  }
}
int size(Node* root) { return root ? root->size : 0; }
int f(Node* root) {
  push(root);
  return root ? root->f : -MAXN;
}
void update(Node* root) {
  if (root) {
    root->size = size(root->left) + size(root->right) + 1;
    push(root);
    root->f = max({root->value, f(root->left), f(root->right)});
  }
}
Node* merge(Node* left, Node* right) {
  push(left), push(right);
  if (!left || !right) return left ? left : right;
  if (left->p > right->p) {
    left->right = merge(left->right, right);
    update(left);
    return left;
  }
  right->left = merge(left, right->left);
  update(right);
  return right;
}
void split(Node* root, int key, int pr, Node*& left, Node*& right) {
  if (!root) return void(left = right = nullptr);
  push(root);
  int cur = size(root->left) + pr + 1;
  if (key > cur) {
    left = root;
    split(root->right, key, cur, root->right, right);
  } else {
    right = root;
    split(root->left, key, pr, left, right->left);
  }
  update(root);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    pos[x] = i;
  }
  for (int i = 0; i < n; ++i) root = merge(root, new Node(0));
  cout << n << ' ';
  int cur = n;
  Node *left, *right;
  split(root, pos[n] + 1, 0, left, right);
  ++left->add;
  root = merge(left, right);
  while (--n) {
    int q;
    cin >> q;
    split(root, q + 1, 0, left, right);
    --left->add;
    root = merge(left, right);
    while (cur > 0) {
      split(root, pos[cur] + 1, 0, left, right);
      if (f(left) > 0) {
        root = merge(left, right);
        break;
      }
      root = merge(left, right);
      if (cur-- > 1) {
        split(root, pos[cur] + 1, 0, left, right);
        ++left->add;
        root = merge(left, right);
      }
    }
    cout << cur << ' ';
  }
  return 0;
}
