#include <bits/stdc++.h>
using namespace std;
const int N = 200009;
int a[N], pos[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    pos[x] = i;
  }
  for (int i = 1; i <= n; i++) a[i] = pos[a[i]];
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      i--;
      cout << n - i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}
