#include <bits/stdc++.h>
using namespace std;
int solveA(vector<int> a, vector<int> b) {
  int n = (int)((a).size());
  vector<int> m(n);
  for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i;
  for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]];
  b[0] = a[0];
  for (int i = (1); i <= ((n - 1)); i++) b[i] = max(b[i - 1], a[i]);
  int res = 0;
  for (int i = (0); i <= ((n)-1); i++) res += (a[i] != b[i]);
  return res;
}
int solveB(vector<int> a, vector<int> b) {
  int res = 0, n = (int)((a).size());
  vector<int> used(n + 1, false);
  while (a.size() || b.size()) {
    if (a.size() && b.size() && a.back() == b.back())
      b.pop_back(), a.pop_back();
    else if (b.size() && used[b.back()])
      b.pop_back();
    else if (a.size() && a.back() != b.back()) {
      used[a.back()] = true;
      a.pop_back();
      res++;
    }
  }
  return res;
}
int solve(vector<int> a, vector<int> b) {
  int n = (int)((a).size());
  vector<int> m(n);
  for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i;
  for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]];
  for (int i = (0); i <= ((n - 1) - 1); i++)
    if (a[i] > a[i + 1]) {
      return n - 1 - i;
    }
  return 0;
}
int main() {
  int n = 100;
  scanf("%d", &n);
  vector<int> a(n), b(n);
  for (int i = (0); i <= ((n)-1); i++) scanf("%d", &a[i]), a[i]--;
  for (int i = (0); i <= ((n)-1); i++) scanf("%d", &b[i]), b[i]--;
  cout << solve(a, b) << endl;
  return 0;
}
