#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? EOF : *ib++;
}
inline int read() {
  char ch = gc();
  int res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline long long readll() {
  char ch = gc();
  long long res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline int readstring(char *s) {
  int top = 0;
  char ch = gc();
  while (isspace(ch)) ch = gc();
  while (!isspace(ch) && ch != EOF) s[++top] = ch, ch = gc();
  return top;
}
template <typename tp>
inline void chemx(tp &a, tp b) {
  a < b ? a = b : 0;
}
template <typename tp>
inline void chemn(tp &a, tp b) {
  a > b ? a = b : 0;
}
const int N = 300005;
int n, p[N], q[N], pos[N];
namespace Seg {
const int N = ::N << 2;
int mx[N], tag[N];
void update(int u, int l, int r, int st, int des, int k) {
  if (st <= l && r <= des) return tag[u] += k, mx[u] += k, void();
  if (st <= ((l + r) >> 1)) update((u << 1), l, ((l + r) >> 1), st, des, k);
  if (((l + r) >> 1) < des)
    update(((u << 1) | 1), ((l + r) >> 1) + 1, r, st, des, k);
  mx[u] = max(mx[(u << 1)], mx[((u << 1) | 1)]) + tag[u];
}
}  // namespace Seg
int main() {
  n = read();
  for (int i = 1; i <= n; i++) p[i] = read(), pos[p[i]] = i;
  for (int i = 1; i <= n; i++) q[i] = read();
  int ans = n + 1;
  for (int i = 1; i <= n; i++) {
    while (Seg::mx[1] <= 0) {
      ans--;
      Seg::update(1, 1, n, 1, pos[ans], 1);
    }
    cout << ans << " ";
    Seg::update(1, 1, n, 1, q[i], -1);
  }
  return 0;
}
