#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
void OPEN(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
map<int, int> pos;
for (int i = 0; i < n; ++i)
cin >> a[i], pos[a[i]] = i;
for (int i = 0; i < n; ++i)
cin >> b[i];
int ans = 0;
ordered_set<int> st;
for (int i = 0; i < n; ++i) {
int ad = st.size() - st.order_of_key(pos[b[i]]);
if (pos[b[i]] + ad > i) {
++ans;
st.insert(pos[b[i]]);
}
}
cout << ans << "\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojaW5jbHVkZSA8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgoKdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7CnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnVzaW5nIG9yZGVyZWRfc2V0ID0gdHJlZTxULG51bGxfdHlwZSxsZXNzPFQ+LHJiX3RyZWVfdGFnLHRyZWVfb3JkZXJfc3RhdGlzdGljc19ub2RlX3VwZGF0ZT47Cgp2b2lkIE9QRU4oc3RyaW5nIHMpIHsKCWZyZW9wZW4oKHMgKyAiLmluIikuY19zdHIoKSwgInIiLCBzdGRpbik7CglmcmVvcGVuKChzICsgIi5vdXQiKS5jX3N0cigpLCAidyIsIHN0ZG91dCk7Cn0KCmludCBtYWluKCkgewoJaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKCWNpbi50aWUoMCk7Cgljb3V0LnRp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