#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
bool v[maxn] = {0};
int main() {
  int n;
  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 j = 1;
  int ans = 0;
  memset(v, 0, sizeof(v));
  for (int i = 1; i <= n && j <= n;) {
    if (a[j] != b[i]) {
      ans++;
      v[b[i]] = 1;
      i++;
    } else {
      i++;
      j++;
      while (j <= n && v[a[j]]) j++;
    };
  }
  printf("%d\n", ans);
  return 0;
}
