#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], w[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    w[b[i]] = i;
  }
  for (int i = 2; i <= n; i++)
    if (w[a[i]] < w[a[i - 1]]) {
      cout << n + 1 - i << "\n";
      return 0;
    }
  cout << 0;
  return 0;
}
