#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 4e6 + 10;
const long long INF = 1e18 + 0;
long long a[N], b[N];
unordered_map<long long, long long> M;
void go() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) M[b[i]] = i;
  for (int i = 0; i < n; i++) a[i] = M[a[i]];
  long long i = 1;
  for (; i < n; i++)
    if (a[i - 1] >= a[i]) break;
  cout << n - i << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    go();
  }
}
