#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int j = -1, pos = 0;
  for (int i = 0; i < n; i++) {
    j = distance(b, find(b + j + 1, b + n, a[i]));
    if (j == n) break;
    pos++;
  }
  cout << n - pos;
  return 0;
}
