#include <bits/stdc++.h>
using namespace std;
vector<int> V;
int N, A[200005], S[200005];
void read() {
  cin >> N;
  int i, x;
  for (int i = 1; i <= N; i++) cin >> S[i];
  for (int i = 1; i <= N; i++) cin >> x, A[x] = i;
}
void solve() {
  int i;
  for (i = 1; i < N; i++)
    if (A[S[i]] > A[S[i + 1]]) break;
  cout << N - i << endl;
}
int main() {
  read();
  solve();
}
