#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
int n;
int a[100001];
int pos[100001];
int b[100001];
set<int> poses;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = n - 1; i >= 0; i--) {
    set<int>::iterator it = poses.lower_bound(pos[b[i]]);
    if (it != poses.begin()) cnt++;
    poses.insert(pos[b[i]]);
  }
  cout << cnt;
  return 0;
}
