#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int a[N], b[N];
int main() {
  int n, i, x;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) scanf("%d", a + i);
    for (i = 1; i <= n; i++) {
      scanf("%d", &x);
      b[x] = i;
    }
    for (i = 1; i < n; i++)
      if (b[a[i]] < b[a[i - 1]]) break;
    printf("%d\n", n - i);
  }
  return 0;
}
