#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long add(long long a, long long b, long long m) {
  return (((a % m + b % m) % m + m) % m);
}
inline long long mul(long long a, long long b, long long m) {
  return (((a % m * b % m) % m + m) % m);
}
const double EPS = 1e-6;
const long long MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
  out << '[' << p.first << ", " << p.second << ']';
  return out;
}
template <template <typename, typename...> class ContainerType,
          typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c) {
  cout << "{ ";
  for (const auto &v : c) cout << v << ' ';
  cout << '}' << '\n';
}
struct Data {
  int mx;
  Data() { mx = 0; }
  Data(long long n) { mx = n; }
};
struct Segtree {
  vector<Data> st;
  vector<long long> lazy;
  int lim, sz;
  Segtree(int n) {
    sz = n;
    lim = 2 * pow(2, ceil(log2(n))) + 1;
    st.assign(lim, Data(0));
    lazy.assign(lim, 0);
  }
  int leftNode(int i) { return 2 * i + 1; }
  int rightNode(int i) { return 2 * i + 2; }
  int parentNode(int i) { return ((i - 1) / 2); }
  void push(int idx, int lo, int hi) {
    if (lazy[idx]) {
      st[leftNode(idx)].mx += lazy[idx];
      st[rightNode(idx)].mx += lazy[idx];
      lazy[leftNode(idx)] += lazy[idx];
      lazy[rightNode(idx)] += lazy[idx];
      lazy[idx] = 0;
    }
  }
  void merge(Data &newn, Data l, Data r) { newn.mx = max(l.mx, r.mx); }
  Data query(int lo, int hi, int idx, int ql, int qr) {
    if (lo > hi || ql > hi || qr < lo) return Data(-1e9);
    if (ql <= lo && hi <= qr) return st[idx];
    push(idx, lo, hi);
    int mid = (lo + hi) / 2;
    Data a = query(lo, mid, 2 * idx + 1, ql, qr);
    Data b = query(mid + 1, hi, 2 * idx + 2, ql, qr);
    if (qr <= mid)
      return a;
    else if (ql > mid)
      return b;
    Data newn;
    merge(newn, a, b);
    return newn;
  }
  void update(int lo, int hi, int idx, int ql, int qr, long long val) {
    if (lo > hi || ql > hi || qr < lo) return;
    if (lo >= ql && hi <= qr) {
      lazy[idx] += val;
      st[idx].mx += val;
      return;
    }
    push(idx, lo, hi);
    int mid = (lo + hi) / 2;
    update(lo, mid, 2 * idx + 1, ql, qr, val);
    update(mid + 1, hi, 2 * idx + 2, ql, qr, val);
    merge(st[idx], st[leftNode(idx)], st[rightNode(idx)]);
  }
  void pointUpdate(int i, long long val) { update(0, sz - 1, 0, i, i, val); }
  void rangeUpdate(int i, int j, long long val) {
    update(0, sz - 1, 0, i, j, val);
  }
  Data pointQuery(int i) { return query(0, sz - 1, 0, i, i); }
  Data rangeQuery(int i, int j) { return query(0, sz - 1, 0, i, j); }
};
void solve() {
  int n;
  cin >> n;
  vector<int> p(n, 0), q(n, 0), idx(n, 0);
  Segtree S(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
    idx[p[i]] = i;
    S.pointUpdate(i, 0);
  }
  for (int i = 0; i < n; i++) cin >> q[i], q[i]--;
  int ans = n - 1;
  S.rangeUpdate(0, idx[ans], 1);
  cout << ans + 1 << " ";
  for (int i = 0; i < n - 1; i++) {
    S.rangeUpdate(0, q[i], -1);
    while (S.rangeQuery(0, n - 1).mx <= 0) {
      ans--;
      S.rangeUpdate(0, idx[ans], 1);
    }
    cout << ans + 1 << " ";
  }
  cout << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  clock_t start, stop;
  int t = 1;
  for (int tc = 1; tc < t + 1; tc++) solve();
  return 0;
}
