#include <bits/stdc++.h>
using namespace std;
int n;
int a[300000];
int main() {
  int b;
  while (cin >> n) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", a + i);
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      cin >> b;
      if (a[cnt] == b) {
        cnt++;
      }
    }
    cout << n - cnt << endl;
  }
  return 0;
}
