#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int a[MAXN], b[MAXN], c[MAXN];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  for (int j = 0; j < n; j++) cin >> b[j], b[j]--;
  for (int j = 0; j < n; j++) c[b[j]] = j;
  int plc = c[a[0]], cnt = 1;
  for (int i = 1; i < n; i++) {
    if (c[a[i]] > plc)
      plc = c[a[i]], cnt++;
    else
      break;
  }
  cout << n - cnt << endl;
  return 0;
}
