#include <bits/stdc++.h>
using namespace std;
const long long LLINF = 1e18;
const int INF = 1e9;
const double EPS = 1e-7;
inline const int &INT() {
  static int x;
  scanf("%d", &x);
  return x;
}
inline const long long &LONG() {
  static long long x;
  scanf("%lld", &x);
  return x;
}
template <class T>
inline void MIN(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void MAX(T &a, const T &b) {
  if (b > a) a = b;
}
const int NN = 2e5 + 5;
int tree[NN], N, A[NN], B[NN], pos[NN], C[NN];
int main() {
  N = INT();
  for (int i = (1); i <= (N); ++i) A[i] = INT();
  for (int i = (1); i <= (N); ++i) B[i] = INT(), pos[B[i]] = i;
  int prev = 0;
  for (int i = (1); i <= (N); ++i) {
    if (prev > pos[A[i]]) {
      cout << N - i + 1 << endl;
      return 0;
    }
    prev = pos[A[i]];
  }
  cout << 0 << endl;
  return 0;
}
