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