#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int n, k;
int a[200005], b[200005], c[200005];
int main() {
  while (~scanf("%d", &n)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &k);
      b[k] = i;
    }
    for (int i = 1; i <= n; i++) c[i] = b[a[i]];
    bool tag = true;
    for (int i = 1; i < n; i++) {
      if (c[i] > c[i + 1]) {
        printf("%d\n", n - i);
        tag = false;
        break;
      }
    }
    if (tag) printf("0\n");
  }
  return 0;
}
