#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
const ld pi = acosl(-1);
const int inf = (int)1e9 + 7;
const ll llinf = (ll)1e18 + 7;
const ld eps = 1e-7;
template <typename T>
inline bool powerof2(T a) {
  return (a && (!(a & (a - 1))));
}
template <typename T>
inline T log_2(T a) {
  T res = -1;
  while (a) {
    a /= 2;
    res++;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  vi pos1(n + 1), pos2(n + 1), order;
  int temp;
  for (int i = (int)(1); i <= (int)(n); i++) {
    cin >> temp;
    pos1[temp] = i;
    order.push_back(temp);
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    cin >> temp;
    pos2[temp] = i;
  }
  int cnt = 0;
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    if (pos2[order[i - 1]] > pos2[order[i]]) {
      swap(order[i], order[i - 1]);
      cnt++;
    }
  }
  cout << cnt << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(15);
  cerr << fixed << setprecision(10);
  solve();
  return 0;
}
