#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 19;
long long p1[maxn], p2[maxn], ind[maxn];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long a, in, ans = 1;
  cin >> a;
  for (long long int i = 0; i < a; i++) cin >> p1[i];
  for (long long int i = 0; i < a; i++) {
    cin >> p2[i];
    ind[p2[i]] = i;
  }
  in = ind[p1[0]];
  for (long long int i = 1; i < a; i++) {
    if (ind[p1[i]] > in) {
      in = ind[p1[i]];
      ans++;
    } else {
      cout << a - ans;
      return 0;
    }
  }
  cout << 0;
  return 0;
}
