#include <bits/stdc++.h>
using namespace std;
int n, arr[200005], brr[200005], vis[200005];
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &arr[i]);
      vis[arr[i]] = i;
    }
    for (int i = 1; i <= n; i++) scanf("%d", &brr[i]);
    int ans = 0, t = 0;
    for (int i = 1; i <= n; i++) {
      arr[vis[brr[i]]] = i;
    }
    arr[n + 1] = 99999999;
    for (int i = 1; i <= n; i++) {
      if (arr[i] > arr[i + 1]) {
        ans = n - i;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
