#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int a[maxn], b[maxn], n;
map<int, int> dict;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  for (int i = 0; i < n; i++) {
    dict[b[i]] = i + 1;
  }
  int c = n - 1;
  for (int i = 0; i + 1 < n && dict[a[i]] < dict[a[i + 1]]; i++) c--;
  cout << c << endl;
  return 0;
}
