#include <bits/stdc++.h>
using namespace std;
int a[200002];
int main() {
  int n;
  scanf("%d", &n);
  map<int, int> index;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    index[a[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    int b;
    scanf("%d", &b);
    a[index[b]] = i;
  }
  int count = n - 1;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] < a[i + 1])
      --count;
    else
      break;
  }
  printf("%d\n", count);
}
