#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx2,avx,fma")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int i, n, l;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int maxi = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  vector<bool> vis(n + 1);
  int j = 0;
  int ans = 0, k;
  for (i = 0; i < n; i++) {
    k = 0;
    if (vis[b[i]]) continue;
    while (b[i] != a[j]) {
      vis[a[j]] = 1;
      j++;
      k++;
    }
    j++;
    ans += k;
  }
  cout << ans;
  return 0;
}
