#include <bits/stdc++.h>
using namespace std;
int INF = 100000000;
double EPS = 1e-8;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), t(2 * 100010, -1);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    t[a[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    int b;
    scanf("%d", &b);
    a[i] = t[b];
  }
  int c = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] == c) c++;
  cout << n - c << endl;
  return 0;
}
