#include <bits/stdc++.h>
template <class T>
inline bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool cmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
char ss[1 << 17], *A = ss, *B = ss;
inline char gc() {
  return A == B && (B = (A = ss) + fread(ss, 1, 1 << 17, stdin), A == B) ? -1
                                                                         : *A++;
}
template <class T>
inline void sd(T& x) {
  char c;
  T y = 1;
  while (c = gc(), (c < 48 || 57 < c) && c != -1)
    if (c == 45) y = -1;
  x = c - 48;
  while (c = gc(), 47 < c && c < 58) x = x * 10 + c - 48;
  x *= y;
}
const int N = 1e5 + 5;
typedef int arr[N];
int n, ans;
arr a, b, c, vis;
int main() {
  sd(n);
  for (register int i = 1, I = n + 1; i < I; ++i) sd(a[i]), c[a[i]] = i;
  for (register int i = 1, I = n + 1; i < I; ++i) sd(b[i]), b[i] = c[b[i]];
  for (int i = 1, Car = 1; i <= n; ++i)
    if (b[i] > Car)
      ++ans, vis[b[i]] = 1;
    else {
      vis[Car] = 1;
      while (vis[Car]) ++Car;
    }
  printf("%d\n", ans);
  return 0;
}
