#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  int b[n + 1];
  int initialpos[n];
  int finalpos[n];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    initialpos[i] = x;
    a[x] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    finalpos[i] = x;
    b[x] = i + 1;
  }
  int lastindex = -1;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      lastindex = b[initialpos[i]];
    } else {
      if (b[initialpos[i]] < lastindex) {
        count++;
      } else {
        lastindex = b[initialpos[i]];
      }
    }
  }
  cout << count << endl;
}
