#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:50000000")
string problem_name = "a";
void init() { freopen((problem_name + ".in").c_str(), "rt", stdin); }
int mas[200100];
int mas2[200100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &mas[i]);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &mas2[i]);
  }
  int pos = 1;
  for (int i = 1; i <= n; i++) {
    while (mas2[pos] != mas[i] && pos <= n) pos++;
    if (pos > n) {
      printf("%d\n", n - i + 1);
      return 0;
    }
    pos++;
  }
  printf("0\n");
  return 0;
}
