#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <typename T>
inline bool remin(T& c, const T& n) {
  if (n < c) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool remin2(T& c, const T& n) {
  if (c < 0 || n < c) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool remax(T& c, const T& n) {
  if (c < n) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline void addmod(T& c, const T& n, const T& m) {
  c = (c + n) % m;
}
int _in;
int in() {
  scanf("%d", &_in);
  return _in;
}
const int N = 2e5 + 5;
int maj[N], nx[N], perm[N];
int main() {
  int n = in(), i;
  for ((i) = (0); (i) < (n); ++(i)) maj[i] = in() - 1;
  for ((i) = (0); (i) < (n); ++(i)) perm[in() - 1] = i;
  for ((i) = (0); (i) < (n); ++(i)) nx[i] = perm[maj[i]];
  set<int, greater<int> > s;
  for ((i) = (0); (i) < (n); ++(i)) {
    s.insert(nx[i]);
    if (*s.begin() != nx[i]) break;
  }
  printf("%d\n", n - i);
  return 0;
}
