#include <bits/stdc++.h>
using namespace std;
int lab[200002];
int a[200002], b[200002];
int maxi[200002];
int main() {
  int n;
  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), lab[b[i]] = i + 1;
  for (int i = 0; i < n; i++) a[i] = lab[a[i]];
  int last = 0;
  for (int i = 1; i < n; i++)
    if (a[i] > a[i - 1])
      last = i;
    else
      break;
  cout << n - last - 1 << endl;
}
