#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2 * 100000 + 5;
int N;
int a[MaxN], b[MaxN], lab[MaxN];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", a + i);
  for (int i = 1; i <= N; ++i) scanf("%d", b + i);
  for (int i = 1; i <= N; ++i) {
    lab[b[i]] = i;
  }
  for (int i = 1; i <= N; ++i) {
    a[i] = lab[a[i]];
  }
  int cnt = 1;
  for (int i = 2; i <= N; ++i)
    if (a[i] > a[i - 1])
      cnt++;
    else
      break;
  cout << N - cnt << endl;
  return 0;
}
