#include <bits/stdc++.h>
using namespace std;
int n, ans, k, a[100005], b[100005], s[100005];
long long Read() {
  long long k = 0, tmp = 1;
  char c = getchar();
  while (c > '9' or c < '0') {
    if (c == '-') tmp = -1;
    c = getchar();
  }
  while (c <= '9' and c >= '0') {
    k = (k << 1) + (k << 3) + (c ^ 48);
    c = getchar();
  }
  return k * tmp;
}
void Work();
int main() { Work(); }
void Work() {
  n = Read();
  for (int i = 1; i <= n; i++) {
    a[i] = Read();
  }
  for (int i = 1; i <= n; i++) {
    b[i] = Read();
  }
  for (int i = 1, j = 1; j <= n; j++) {
    if (a[i] == b[j]) {
      ans++;
      i++;
    }
    while (s[a[i]]) i++;
    s[b[j]] = true;
  }
  printf("%d\n", n - ans);
}
