#include <bits/stdc++.h>
using namespace std;
int n, a[200100], b[200100];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    b[x] = i;
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = b[a[i]];
    if (a[i - 1] < a[i])
      mx++;
    else
      break;
  }
  cout << n - mx;
}
