#include <bits/stdc++.h>
using namespace std;
int A[200010];
int B[200010];
int C[200010];
int main() {
  int n;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) scanf("%d ", &A[i]);
  scanf("\n");
  for (int i = 1; i <= n; i++) scanf("%d ", &B[i]);
  for (int i = 1; i <= n; i++) C[B[i]] = i;
  int cnt = 0;
  for (int i = 1, tmp = 0; i <= n; i++, cnt++) {
    if (tmp > C[A[i]]) break;
    tmp = C[A[i]];
  }
  cout << n - cnt;
  return (0);
}
