#include <bits/stdc++.h>
using namespace std;
int a[200100];
int b[200100];
int p[200100];
int m[200100];
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]);
    p[b[i]] = i;
  }
  int res = 0;
  m[0] = p[a[0]];
  for (int i = (1); i < (n); ++i)
    m[i] = ((m[i - 1] < p[a[i]]) ? (p[a[i]]) : (m[i - 1]));
  for (int i = n - 1; i > 0; --i)
    if (m[i - 1] > p[a[i]]) res = n - i;
  cout << res << endl;
  return 0;
}
