#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200010;
queue<long long> q;
bool vis[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    q.push(a);
  }
  long long bad = 0;
  for (long long i = 0; i < n; i++) {
    long long out;
    cin >> out;
    while (vis[q.front()]) q.pop();
    if (out != q.front()) {
      bad++;
      vis[out] = true;
    } else
      q.pop();
  }
  cout << bad << endl;
  return 0;
}
