#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:400000000")
int n, a[200010], b[200010], f[200010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    f[x - 1] = i;
  }
  for (int i = 0; i < n; i++) b[i] = f[a[i] - 1];
  for (int i = 1; i < n; i++) {
    if (b[i] < b[i - 1]) {
      cout << n - i;
      return 0;
    }
  }
  cout << 0;
}
