#include <bits/stdc++.h>
using namespace std;
const int Nmax = 200005;
int A[Nmax], B[Nmax], PosB[Nmax];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  for (int i = 1; i <= N; ++i) cin >> B[i];
  for (int i = 1; i <= N; ++i) PosB[B[i]] = i;
  int maxp = 0, ans = N;
  for (int i = 1; i <= N; ++i) {
    maxp = max(maxp, PosB[A[i]]);
    if (PosB[A[i]] < maxp) {
      ans = i - 1;
      break;
    }
  }
  ans = N - ans;
  cout << ans << '\n';
}
