#include <bits/stdc++.h>
using namespace std;
int pos[200010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n + 11], b[n + 11];
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    pos[b[i]] = i;
  }
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (pos[a[i]] > pos[a[i - 1]])
      cnt++;
    else
      break;
  }
  cout << n - cnt;
  return 0;
}
