#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200007;
int a[MAX_N], p[MAX_N];
int main() {
  int n;
  cin >> n;
  for (int i = int(1); i <= int(n); ++i) scanf("%d", &a[i]);
  for (int i = int(1); i <= int(n); ++i) {
    int x;
    scanf("%d", &x);
    p[x] = i;
  }
  for (int i = int(1); i <= int(n); ++i) a[i] = p[a[i]];
  int y = n + 1, maxA = 0;
  for (int i = int(1); i <= int(n); ++i) {
    if (y > n && maxA > a[i]) y = i;
    maxA = max(maxA, a[i]);
  }
  cout << n - y + 1;
  return 0;
}
