#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, cnt = 0, fl;
int a[N], b[N];
int c[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  fl = n - 1;
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] == a[j]) {
      j++;
      continue;
    }
    if (c[b[i]]) continue;
    while (c[b[i]] == 0) {
      cnt++;
      c[a[fl--]] = 1;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
