#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N;
  cin >> N;
  int p[N + 1];
  queue<int> q;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    p[x] = i;
    q.push(x);
  }
  int res = 0;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    if (!q.empty() && p[q.front()] < p[x]) {
      ++res;
      p[x] = -1;
    }
    while (!q.empty() && (p[q.front()] == -1 || q.front() == x)) {
      q.pop();
    }
  }
  cout << res;
  return 0;
}
