#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int a[200005], b[200005], pos[200005];
int main() {
  int i, j, n, ret = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    pos[b[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    if (pos[a[i]] < pos[a[i - 1]]) {
      ret += (n - i);
      break;
    }
  }
  cout << ret << endl;
  return 0;
}
