#include <bits/stdc++.h>
using namespace std;
long long int a[2][200500];
long long int pos[200500];
int main() {
  long long int n;
  cin >> n;
  for (long long int i = 0; i < ((long long int)(2)); ++i)
    for (long long int j = 0; j < ((long long int)(n)); ++j) cin >> a[i][j];
  for (long long int i = 0; i < ((long long int)(n)); ++i) pos[a[1][i]] = i;
  long long int last = -1;
  for (long long int i = 0; i < ((long long int)(n)); ++i) {
    if (last < pos[a[0][i]]) {
      last = pos[a[0][i]];
    } else {
      cout << n - i << endl;
      break;
    }
    if (i + 1 == n) cout << 0 << endl;
  }
}
