#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
int pos[N];
int a[N], b[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
    pos[b[i]] = i;
  }
  int i;
  for (i = 1; i < n; ++i) {
    if (pos[a[i]] < pos[a[i - 1]]) {
      break;
    }
  }
  printf("%d\n", n - i);
  return 0;
}
