#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 13;
int n, a[maxN], mp[maxN], ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x] = i + 1;
  }
  for (int i = 0; i < n; i++) a[i] = mp[a[i]];
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1])
      ans++;
    else
      break;
  }
  cout << n - ans - 1 << endl;
}
