#include <bits/stdc++.h>
using namespace std;
int n;
int a[200001];
int pos[200001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  for (int i = 2; i <= n; i++)
    if (pos[a[i]] < pos[a[i - 1]]) {
      cout << n - (i - 1) << endl;
      return 0;
    }
  cout << 0 << endl;
  return 0;
}
