#include <bits/stdc++.h>
using namespace std;
vector<long long int> pos(300005);
long long int powmod(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
using S = long long int;
vector<S> a(300005), b(300005);
typedef struct data {
  S val;
} data;
struct data tree[4 * 300005];
struct data lazy[4 * 300005];
struct data combine(struct data l, struct data r) {
  struct data res;
  res.val = min(l.val, r.val);
  return res;
}
struct data make_data(S val, S ind) {
  struct data res;
  res.val = val;
  return res;
}
void build(S vector, S tl, S tr) {
  if (tl == tr) {
    tree[vector] = make_data(a[tl], tl);
  } else {
    S tm = (tl + tr) / 2;
    build(vector * 2, tl, tm);
    build(vector * 2 + 1, tm + 1, tr);
    tree[vector] = combine(tree[vector * 2], tree[vector * 2 + 1]);
  }
}
void push(S node) {
  tree[node * 2].val += lazy[node].val;
  lazy[node * 2].val += lazy[node].val;
  tree[node * 2 + 1].val += lazy[node].val;
  lazy[node * 2 + 1].val += lazy[node].val;
  lazy[node].val = 0;
}
struct data query(S node, S tl, S tr, S l, S r) {
  if (l > r) return make_data(0, 0);
  if (l == tl && r == tr) {
    return tree[node];
  }
  push(node);
  S tm = (tl + tr) / 2;
  struct data temp =
      combine(query(node * 2, tl, tm, l, min(r, tm)),
              query(node * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
  return temp;
}
void update(S vector, S tl, S tr, S pos, S new_val) {
  if (tl == tr) {
    tree[vector] = make_data(new_val, tl);
  } else {
    S tm = (tl + tr) / 2;
    if (pos <= tm)
      update(vector * 2, tl, tm, pos, new_val);
    else
      update(vector * 2 + 1, tm + 1, tr, pos, new_val);
    tree[vector] = combine(tree[vector * 2], tree[vector * 2 + 1]);
  }
}
void update1(S node, S tl, S tr, S l, S r, S addend) {
  if (l > r) return;
  if (l == tl && tr == r) {
    tree[node].val += addend;
    lazy[node].val += addend;
  } else {
    push(node);
    S tm = (tl + tr) / 2;
    update1(node * 2, tl, tm, l, min(r, tm), addend);
    update1(node * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);
    tree[node] = combine(tree[node * 2], tree[node * 2 + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  long long int ans = n;
  long long int ind = 1;
  for (long long int i = 1; i <= n; i++) {
    while (true) {
      update1(1, 1, n, 1, pos[ans], -1);
      if (tree[1].val >= 0)
        ans--;
      else {
        update1(1, 1, n, 1, pos[ans], 1);
        break;
      }
    }
    cout << ans << " ";
    update1(1, 1, n, 1, b[i], 1);
  }
  cout << "\n";
}
