#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
vector<int> v;
int a[maxn], b[maxn];
map<int, int> mark, mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) mp[a[i]] = i;
  for (int i = 1; i <= n; i++) b[i] = mp[b[i]];
  for (int i = 2; i <= n; i++)
    if (b[i] < b[i - 1]) return (cout << n - i + 1 << endl, 0);
  return (cout << 0 << endl, 0);
}
