#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int a[MAXN], b[MAXN], c[MAXN];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    c[b[i] - 1] = i;
  }
  for (int i = 0; i < n; ++i) {
    a[i] = c[a[i]];
  }
  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      break;
    }
    ++ans;
  }
  cout << n - ans - 1;
}
