#include <bits/stdc++.h>
using namespace std;
class segmentTree {
 public:
  int* tree;
  int* lazyTree;
  int N;
  int size;
  void printTree() {
    for (int i = 0; i < size; i++) {
      cout << tree[i] << ' ';
    }
    cout << '\n';
  }
  void update(int qleft, int qright, int delta) {
    update(qleft, qright, delta, 0, N - 1, 0);
  }
  void update(int qleft, int qright, int delta, int left, int right,
              int index) {
    if (lazyTree[index] != 0) {
      int change = lazyTree[index];
      tree[index] += lazyTree[index];
      lazyTree[index] = 0;
      if (left != right) {
        lazyTree[2 * index + 1] += change;
        lazyTree[2 * index + 2] += change;
      }
    }
    if (left >= qleft && right <= qright) {
      tree[index] += delta;
      if (left != right) {
        lazyTree[2 * index + 1] += delta;
        lazyTree[2 * index + 2] += delta;
      }
    } else if (!(right < qleft || left > qright)) {
      int mid = (left + right) / 2;
      update(qleft, qright, delta, left, mid, 2 * index + 1);
      update(qleft, qright, delta, mid + 1, right, 2 * index + 2);
      tree[index] = max(tree[2 * index + 1], tree[2 * index + 2]);
    }
  }
  int rmq(int qleft, int qright) { return rmq(qleft, qright, 0, N - 1, 0); }
  int rmq(int qleft, int qright, int left, int right, int index) {
    if (lazyTree[index] != 0) {
      int change = lazyTree[index];
      tree[index] += lazyTree[index];
      lazyTree[index] = 0;
      if (left != right) {
        lazyTree[2 * index + 1] += change;
        lazyTree[2 * index + 2] += change;
      }
    }
    if (left >= qleft && right <= qright) {
      return tree[index];
    }
    if (right < qleft || left > qright) {
      return INT_MIN;
    }
    int mid = (left + right) / 2;
    return max(rmq(qleft, qright, left, mid, 2 * index + 1),
               rmq(qleft, qright, mid + 1, right, 2 * index + 2));
  }
  void createTree(vector<int>& arr, int left, int right, int index) {
    if (left == right) {
      tree[index] = arr[left];
    } else {
      int mid = (left + right) / 2;
      createTree(arr, left, mid, 2 * index + 1);
      createTree(arr, mid + 1, right, 2 * index + 2);
      tree[index] = max(tree[2 * index + 1], tree[2 * index + 2]);
    }
  }
  segmentTree() {
    N = 3e5 + 69;
    int start = 2;
    while ((start - 1) < 2 * N) start *= 2;
    size = start - 1;
    tree = new int[size];
    for (int i = 0; i < size; i++) {
      tree[i] = 0;
    }
    lazyTree = new int[size];
    memset(lazyTree, 0, size * sizeof(int));
  }
};
const int W = 3e5 + 69;
int idx[W];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    idx[t] = i;
  }
  int ans = n;
  segmentTree tree = segmentTree();
  cout << ans << ' ';
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    b--;
    if (i == n - 1) continue;
    tree.update(0, b, -1);
    while (tree.rmq(0, W - 20) <= 0 && ans > 0) {
      tree.update(0, idx[ans], 1);
      ans--;
    }
    cout << ans + 1 << ' ';
  }
}
