#include <bits/stdc++.h>
using namespace std;
int n, a[222222], pos[222222];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  int r = n;
  for (int i = 1; i < n; ++i)
    if (pos[a[i]] > pos[a[i + 1]]) {
      r = i;
      break;
    }
  cout << n - r << endl;
  return 0;
}
