#include <bits/stdc++.h>
using namespace std;
int mp[200005];
int a[200005];
int n;
int main() {
  int y, T, n, m, i, t, j, k, x;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    mp[x] = i + 1;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    a[i] = mp[x];
  }
  int c = 1;
  int ans = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == c) {
      c++;
      ans++;
    }
  }
  printf("%d\n", n - ans);
  return 0;
}
