#include <bits/stdc++.h>
using namespace std;
mt19937 myrand(time(0));
bool isprime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
long long modexp(long long a, long long b, long long m) {
  long long r = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) r = (r * a) % m;
    b = b >> 1;
    a = (a * a) % m;
  }
  return r % m;
}
long long builtin_popcount(long long x) {
  long long cnt = 0;
  for (long long i = 60; i >= 0; i--) {
    if ((1LL << i) & x) cnt++;
  }
  return cnt;
}
long long addmod(long long a, long long b) {
  a %= 998244353;
  b %= 998244353;
  return (a + b) % 998244353;
}
long long mulmod(long long a, long long b) {
  a %= 998244353;
  b %= 998244353;
  return (a * b) % 998244353;
}
long long submod(long long a, long long b) {
  a %= 998244353;
  b %= 998244353;
  a -= b;
  if (a < 0) a += 998244353;
  return a % 998244353;
}
struct CustomCompare {
  bool operator()(long long a, long long b) { return a > b; }
};
const int mxn = 3e5 + 10;
long long neutral = 1e18;
long long tree[4LL * mxn], operation[4LL * mxn];
long long combine(long long a, long long b) { return min(a, b); }
void apply(long long v, long long val) {
  tree[v] += val;
  operation[v] += val;
}
void propogate(long long v, long long tl, long long tr) {
  if (operation[v] == 0 || tl == tr) return;
  apply(2 * v, operation[v]);
  apply(2 * v + 1, operation[v]);
  operation[v] = 0;
}
void update(long long v, long long tl, long long tr, long long l, long long r,
            long long val) {
  if (tl > r || l > tr) return;
  if (tl == l && tr == r) {
    apply(v, val);
    return;
  }
  propogate(v, tl, tr);
  long long mid = tl + (tr - tl) / 2;
  update(2 * v, tl, mid, l, min(mid, r), val);
  update(2 * v + 1, mid + 1, tr, max(mid + 1, l), r, val);
  tree[v] = combine(tree[2 * v], tree[2 * v + 1]);
}
long long query(long long v, long long tl, long long tr, long long l,
                long long r) {
  if (tl > r || l > tr) return neutral;
  if (tl == l && tr == r) return tree[v];
  propogate(v, tl, tr);
  long long mid = tl + (tr - tl) / 2;
  return combine(query(2 * v, tl, mid, l, min(mid, r)),
                 query(2 * v + 1, mid + 1, tr, max(mid + 1, l), r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    arr[x - 1] = i;
  }
  long long ans = n - 1;
  update(1, 0, n - 1, 0, arr[n - 1], -1);
  for (int i = 0; i < n; i++) {
    while (query(1, 0, n - 1, 0, n - 1) >= 0) {
      update(1, 0, n - 1, 0, arr[ans - 1], -1);
      ans--;
    }
    cout << ans + 1 << " ";
    long long q;
    cin >> q;
    update(1, 0, n - 1, 0, q - 1, 1);
  }
  return 0;
}
