#include <bits/stdc++.h>
using namespace std;
int vis[500500];
int a[500500];
int b[500500];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < n; j++) cin >> b[j];
  int ans = 0;
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (vis[a[i]]) continue;
    while (j < n && b[j] != a[i]) {
      vis[b[j]] = 1;
      ans++;
      j++;
    }
    if (j < n && a[i] == b[j]) j++;
  }
  cout << ans << endl;
  return 0;
}
