#include <bits/stdc++.h>
using namespace std;
int a[1100000], b[1100000], c[1100000];
int main() {
  int i, n, ans;
  cin >> n;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (i = 1; i <= n; i++) c[b[i]] = i;
  for (i = 1; i <= n; i++) b[i] = c[a[i]];
  ans = n;
  b[0] = 0;
  for (i = 1; i <= n; i++)
    if (b[i] > b[i - 1])
      ans--;
    else
      break;
  cout << ans << endl;
  return 0;
}
