#include <bits/stdc++.h>
const int N = 200000 + 5;
int n;
int an[N], bn[N], atbn[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &an[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &bn[i]);
  for (int i = 1; i <= n; ++i) atbn[bn[i]] = i;
  for (int i = 1; i <= n; ++i) {
    if (i > 1 && atbn[an[i]] < atbn[an[i - 1]]) {
      printf("%d\n", n - i + 1);
      return 0;
    }
  }
  puts("0");
  return 0;
}
