#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> perm1(N), perm2(N);
  for (int i = 0, _n = N; i < _n; i++) cin >> perm1[i];
  for (int i = 0, _n = N; i < _n; i++) cin >> perm2[i];
  vector<int> index(N + 1);
  for (int i = 0, _n = N; i < _n; i++) index[perm2[i]] = i;
  int prev = -1;
  for (int i = 0, _n = N; i < _n; i++) {
    if (index[perm1[i]] > prev) {
      prev = index[perm1[i]];
    } else {
      cout << N - i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}
