#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (int)1e9;
const int MAX_N = 200 * 1000 + 1000;
int n;
int a[MAX_N], b[MAX_N], trans[MAX_N];
int mark[MAX_N];
void f() {
  for (int i = 0; i < n; i++) {
    trans[b[i]] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    a[i] = trans[a[i]];
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  f();
  int ans = 0;
  mark[0] = 2;
  for (int i = 0; i < n; i++) {
    if (mark[a[i]]) continue;
    mark[a[i]] = 2;
    for (int j = a[i] - 1; mark[j] == 0; j--) {
      ans++;
      mark[j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (mark[a[i]] == 2) {
      bool flag = 0;
      for (int j = i + 1; j < n; j++) {
        if (mark[a[j]] == 1) flag = 1;
        if (mark[a[j]] == 2 && flag == 1) {
          ans++;
        }
      }
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
