#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int arr[100005], dp[100005];
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  queue<int> q;
  int d;
  int cnt = 0;
  std::map<int, int> h1;
  for (int i = 0; i < n; ++i) {
    cin >> d;
    h1[d] = i;
  }
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i <= n + 1; ++i) {
    dp[i] = mod;
  }
  for (int i = n - 1; i >= 0; i--) {
    dp[i] = min(dp[i + 1], h1[arr[i]]);
  }
  for (int i = 0; i < n; ++i) {
    if (h1[arr[i]] > dp[i + 1]) cnt++;
  }
  cout << endl;
  cout << cnt;
  return 0;
}
