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