#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200 * 1000 + 10;
int n, arr[Maxn], ind[Maxn], ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    ind[a] = i;
  }
  int prev = 0;
  for (int i = 0; i < n; i++) {
    if (ind[arr[i]] < prev) {
      cout << n - i << endl;
      return 0;
    }
    prev = ind[arr[i]];
  }
  cout << 0 << endl;
  return 0;
}
