#include <bits/stdc++.h>
using namespace std;
int arr1[121212], arr2[121212];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, ans = 0;
  cin >> N;
  map<int, int> m;
  for (int i = 1; i <= N; i++) {
    cin >> arr1[i];
  }
  for (int i = 1; i <= N; i++) {
    cin >> arr2[i];
  }
  int j = 1;
  for (int i = 1; i <= N && j <= N; i++) {
    if ((arr1[i] != arr2[j])) {
      if (!m[arr1[i]]) {
        while ((arr1[i] != arr2[j]) && j <= N) {
          ans++;
          m[arr2[j]] = 1;
          j++;
        }
        m[arr1[i]] = 1;
        j++;
      }
    } else {
      m[arr2[j]] = 1;
      j++;
    }
  }
  cout << ans << endl;
}
