#include <bits/stdc++.h>
using namespace std;
const int N = 203600;
int a[N], b[N], n;
int pos[N];
bool vis[N];
int main() {
  while (cin >> n) {
    memset(vis, 0, sizeof(vis));
    for (int i = (1); i <= (int)(n); i++) cin >> a[i];
    for (int i = (1); i <= (int)(n); i++) {
      int first;
      cin >> first;
      b[first] = i;
    }
    for (int i = (1); i <= (int)(n); i++) a[i] = b[a[i]];
    for (int i = (1); i <= (int)(n); i++) pos[a[i]] = i;
    int ans = 0;
    int s = 1, e = n;
    for (int s = 1, i = 1; s <= n; s++) {
      if (vis[s]) continue;
      if (a[i] == s) {
        i++;
        continue;
      }
      int p = pos[s];
      while (e >= p) {
        ans++;
        vis[a[e]] = true;
        e--;
      }
    }
    cout << ans << endl;
  }
}
