#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
  os >> p.first >> p.second;
  return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
  if (v.empty()) return os;
  if (v.begin() != v.end()) os << v.front();
  for (auto it = ++v.begin(); it != v.end(); ++it) os << ' ' << *it;
  return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <class T, size_t N>
inline istream& operator>>(istream& is, array<T, N>& a) {
  for (auto& i : a) is >> i;
  return is;
}
struct hasher {
  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);
  }
};
void Solve(istream& is, ostream& os) {
  int n;
  is >> n;
  vector<int> a(n), b_pos(n);
  for (register int i = 0; i < n; ++i) {
    is >> a[i];
    --a[i];
  }
  for (register int i = 0; i < n; ++i) {
    int next;
    is >> next;
    b_pos[next - 1] = i;
  }
  int mx = -1, res = 0;
  for (register int i = 0; i < n; ++i) {
    int c = b_pos[a[i]];
    if (c < mx) {
      ++res;
    } else {
      mx = c;
    }
  }
  os << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << setprecision(20) << fixed;
  Solve(cin, cout);
  return 0;
}
