#include <bits/stdc++.h>
using namespace std;
int a[200050], b[200050], rel_a[200050], inver_b[200050];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      inver_b[b[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
      rel_a[i] = inver_b[a[i]];
    }
    int i = 1;
    for (i = 1; i <= n - 1; i++) {
      if (rel_a[i] > rel_a[i + 1]) break;
    }
    cout << n - i << endl;
  }
  return 0;
}
