#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n], b[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[ans] == b[i]) {
      ans += 1;
    }
  }
  cout << n - ans;
  return 0;
}
