#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int ans = 0;
    vector<int> v1, v2, v3;
    for (i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      v1.push_back(temp);
    }
    for (i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      v2.push_back(temp);
      v3.push_back(0);
    }
    v3.push_back(0);
    i = 0;
    j = 0;
    while (i < n && j < n) {
      if (v3[v1[i]] != 0) {
        i++;
      } else if (v1[i] != v2[j]) {
        v3[v2[j]] = 1;
        j++;
        ans++;
      } else {
        v3[v2[j]]++;
        i++;
        j++;
      }
    }
    cout << ans << '\n';
  }
}
