#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, a[N], b[N], cnt, last, cnt1;
set<int> s;
bool inline inside(int x) { return x >= 1 && x <= n; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  last = n;
  for (int i = 1; i <= n; i++) {
    if (inside(i - cnt1) && a[i - cnt1] == b[i]) continue;
    if (s.find(b[i]) != s.end()) {
      cnt1++;
      continue;
    }
    for (;;) {
      cnt++;
      if (a[last] == b[i]) {
        cnt1++;
        last--;
        break;
      }
      s.insert(a[last]);
      last--;
    }
  }
  printf("%d", cnt);
}
