#include <bits/stdc++.h>
using namespace std;
int place[220000], a[2100000];
int n;
int main() {
  int temp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    place[a[i]] = i;
  }
  int ans = 0, p = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    if (temp == a[p])
      p++;
    else
      ans++;
  }
  cout << ans;
  return 0;
}
