#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
long long int rng(long long int lim) {
  uniform_int_distribution<long long int> uid(0, lim - 1);
  return uid(rang);
}
long long int mpow(long long int base, long long int exp);
void ipgraph(long long int n, long long int m);
void dfs(long long int u, long long int par);
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> posin(n + 1);
  vector<long long int> posout(n + 1);
  vector<long long int> in(n);
  vector<long long int> out(n);
  for (long long int i = n - 1; i >= 0; i--) {
    cin >> in[i];
    posin[in[i]] = i;
  }
  for (long long int i = n - 1; i >= 0; i--) {
    cin >> out[i];
    posout[out[i]] = n - i;
  }
  long long int maxi = 0, cnt = 0;
  vector<long long int> c;
  for (long long int i = 0; i < n; i++) {
    c.push_back(posout[in[i]]);
  }
  for (long long int i = n - 1; i >= 0; i--) {
    if (c[i] < maxi) {
      cnt++;
    }
    maxi = max(maxi, c[i]);
  }
  cout << cnt << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
long long int mpow(long long int base, long long int exp) {
  base %= 1000000007;
  long long int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long int)result * base) % 1000000007;
    base = ((long long int)base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
