#include <bits/stdc++.h>
using namespace std;
void k_007() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long prime(long long n) {
  long long flag = 1;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      flag = 0;
      break;
    }
  }
  return flag;
}
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ((power(x, y / 2) % 1000000007) * (power(x, y / 2) % 1000000007)) %
           1000000007;
  else
    return ((x % 1000000007) * (power(x, y / 2) % 1000000007) *
            (power(x, y / 2) % 1000000007)) %
           1000000007;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int32_t main() {
  k_007();
  long long n;
  cin >> n;
  long long enter[n], exit[n];
  map<long long, long long> en, ex;
  for (long long i = 0; i < n; i++) {
    cin >> enter[i];
    en[enter[i]] = i;
  }
  for (long long i = 0; i < n; i++) {
    cin >> exit[i];
    ex[exit[i]] = i;
  }
  for (long long i = 0; i < n; i++) {
    en[enter[i]] = ex[enter[i]];
  }
  long long ans = 0;
  long long maxi = -1;
  for (long long i = 0; i < n; i++) {
    if (en[enter[i]] > maxi) {
      maxi = en[enter[i]];
    } else
      ++ans;
  }
  cout << ans << endl;
}
