#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
bool isprime(long long int a) {
  if (a == 1) return false;
  if (a == 2) return true;
  if (a % 2 == 0) return false;
  for (long long int i = 3; (i * i) <= a; i += 2) {
    if (a % i == 0) return false;
  }
  return true;
}
int main() {
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    bool hascome[n + 5];
    hascome[n] = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      hascome[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    int ap = 0;
    int bp = 0;
    int cnt = 0;
    int fine = 0;
    while (cnt < n) {
      if (b[bp] == a[ap]) {
        hascome[a[ap]] = 1;
        cnt += 1;
        ap += 1;
        bp += 1;
      } else {
        if (hascome[a[ap]]) {
          ap += 1;
        } else {
          hascome[b[bp]] += 1;
          fine += 1;
          cnt += 1;
          bp += 1;
        }
      }
    }
    cout << fine << endl;
  }
  return 0;
}
