#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int, greater<int>> input;
  map<int, int, greater<int>> output;
  map<int, int, greater<int>> input_reverse;
  map<int, int, greater<int>> output_reverse;
  int N;
  scanf("%d", &N);
  ;
  int i = N;
  int index = 1;
  while (i--) {
    int x;
    scanf("%d", &x);
    input[index] = x;
    input_reverse[x] = index;
    index++;
  }
  i = N;
  index = 1;
  while (i--) {
    int x;
    scanf("%d", &x);
    output[index] = x;
    output_reverse[x] = index;
    index++;
  }
  map<int, int, greater<int>>::iterator it1;
  int val = 0;
  int count_val = 0;
  it1 = input.begin();
  while (!input.empty()) {
    int x = (*it1).second;
    if (x != (*(output.begin())).second) {
      val = val + count_val + 1;
      count_val = 0;
    } else {
      count_val++;
    }
    it1++;
    input.erase((*(input_reverse.find(x))).second);
    output.erase((*(output_reverse.find(x))).second);
  }
  printf("%d\n", val);
}
