#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int N;
int A[MAXN], B[MAXN];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i <= N; i++) {
    int x;
    scanf("%d", &x);
    B[x] = i;
  }
  for (int i = 1; i <= N; i++) {
    A[i] = B[A[i]];
  }
  int ans = 1;
  for (int i = 2; i <= N; i++) {
    if (A[i] < A[i - 1]) {
      break;
    }
    ans++;
  }
  printf("%d\n", N - ans);
}
