#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000000];
int b[2000000];
int ma[2000000];
int ra[2000000];
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      ma[a[i]] = i;
    }
    for (int i = 0; i < n; ++i) {
      scanf("%d", &b[i]);
      ra[ma[b[i]]] = i;
    }
    int j;
    int big = -1;
    for (j = 0; j < n; ++j) {
      if (ra[j] < big)
        break;
      else {
        big = ra[j];
      }
    }
    cout << n - j << endl;
  }
  return 0;
}
