#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int a1[MAXN], a2[MAXN], pos[MAXN];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> a1[i];
    }
    int cnt = 1;
    for (int i = 1; i <= n; i++) {
      cin >> a2[i];
      pos[a2[i]] = i;
    }
    int pre = pos[a1[1]];
    for (int i = 2; i <= n; i++) {
      if (pos[a1[i]] > pre)
        cnt++;
      else
        break;
      pre = pos[a1[i]];
    }
    cout << n - cnt << endl;
  }
  return 0;
}
