#include <bits/stdc++.h>
using namespace std;
template <class T>
bool checkMin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool checkMax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const int MN = 1e5 + 1e5 + 100;
int n, x, a[MN], pos[MN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", a + i);
  for (int i = 0; i < (n); i++) scanf("%d", &x), pos[x] = i;
  for (x = 1; x < n; x++)
    if (pos[a[x]] < pos[a[x - 1]]) break;
  printf("%d\n", n - x);
}
