#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long infl = 1LL << 60;
char buf[1000000];
string nextLine() {
  scanf("%[^\n]", buf);
  scanf("%*c");
  return string(buf);
}
string next() {
  scanf("%s", buf);
  return string(buf);
}
int nextInt() {
  int tmp;
  scanf("%d", &tmp);
  return tmp;
}
const int MAXN = 1000100;
int ar[MAXN], ar2[MAXN];
int main() {
  int N = nextInt();
  for (int i = 0, _i = (N); i < _i; ++i) {
    ar2[i] = nextInt() - 1;
  }
  for (int i = 0, _i = (N); i < _i; ++i) {
    ar[nextInt() - 1] = i;
  }
  int pr = -1;
  int cnt = 0;
  for (int i = 0, _i = (N); i < _i; ++i) {
    if (ar[ar2[i]] > pr) {
      pr = ar[ar2[i]];
      cnt++;
    } else
      break;
  }
  cout << N - cnt << endl;
}
