#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";
}