#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
void cp() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  map<int, int> pos;
  for (int &x : a) cin >> x;
  for (int i = 0; i < n; i++) cin >> b[i], pos[b[i]] = i;
  int cnt = 0;
  int last = -1;
  for (int i = 0; i < n; i++) {
    int at = pos[a[i]];
    if (at > last)
      cnt++, last = at;
    else
      break;
  }
  cout << n - cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
