#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, ans = 0;
  cin >> n;
  vector<int> a(n + 5), b(n + 5), c(n + 5);
  map<long long, long long> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i], m[b[i]] = i;
  for (int i = 0; i < n; i++) c[i + 1] = m[a[i + 1]];
  for (int i = 0; i < n - 1; i++)
    if (c[i + 2] > c[i + 1])
      ans++;
    else
      break;
  cout << n - ans - 1;
  return 0;
}
