#include <bits/stdc++.h>
using namespace std;
const long long N = (int)2e5 + 74, OO = 0x3f3f3f3f, MOD = (int)1e9 + 7;
class CPermutations {
 public:
  void init() {}
  void solve(istream& cin, ostream& cout) {
    init();
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    map<int, int> idx;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      idx[b[i]] = i;
    }
    int mx = 1;
    for (int i = 1; i < n; i++) {
      if (idx[a[i]] > idx[a[i - 1]])
        ++mx;
      else
        break;
    }
    cout << n - mx << '\n';
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  CPermutations solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
