#include <bits/stdc++.h>
using namespace std;
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
long long gcd(long long a, long long b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long i, n, j, d, sl, tl, k;
  long long *a = new long long[300000], *b = new long long[300000],
            *c = new long long[300000], *x = new long long[300000];
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    c[a[i]] = i + 1;
  }
  for (i = 0; i < n; ++i) {
    cin >> b[i];
    x[b[i]] = i + 1;
  }
  k = 1;
  i = 1;
  while (i < n && x[a[i]] > x[a[i - 1]]) {
    k++;
    ++i;
  }
  cout << n - k;
  return 0;
}
