#include <bits/stdc++.h>
using namespace std;
int p_arr[200005];
int main() {
  int n, in, cnt, x, arr[200005];
  std::cin >> n;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    std::cin >> in;
    q.push(in);
  }
  for (int i = 1; i <= n; i++) {
    std::cin >> arr[i];
  }
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    x = q.front();
    while (p_arr[x] == -1) {
      q.pop();
      x = q.front();
    }
    x = q.front();
    if (x == arr[i]) {
      q.pop();
    } else {
      cnt++;
      p_arr[arr[i]] = -1;
    }
  }
  std::cout << cnt << '\n';
  return 0;
}
