#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long int prod(long long int a, long long int b) {
  long long int res = 0;
  a %= 1000000007;
  while (b) {
    if (b & 1ll) res = (res + a) % 1000000007;
    a = (2ll * a) % 1000000007;
    b >>= 1ll;
  }
  return res;
}
long long int power(long long int a, long long int b) {
  long long int res = 1ll;
  while (b > 0) {
    if (b % 2ll) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2ll;
  }
  return res;
}
long long int binaryExponentiation(long long int a, long long int b) {
  long long int result = 1ll;
  while (b > 0) {
    if (b % 2 == 1) result = (result * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2ll;
  }
  return result;
}
long long int ModularInverse(long long int a) {
  return binaryExponentiation(a, 1000000007 - 2);
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v1(n), v2(n);
  map<long long int, long long int> mp1, mp2;
  for (long long int i = 0; i < n; i++) {
    cin >> v1[i];
    mp1[v1[i]] = i;
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> v2[i];
    ans += (v1[ans] == v2[i]);
  }
  cout << n - ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
}
