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