#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 100000 + 1;
const int MOD = 1000000007;
const long long MAX = 10000000000;
int n, a[N], b[N], num[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
    num[b[i]] = i;
  }
  int mx = -1, ans = 0;
  for (int i = 0; i < n; ++i) {
    if (num[a[i]] < mx) {
      ans++;
    }
    mx = max(mx, num[a[i]]);
  }
  cout << ans << endl;
  return 0;
}
