#include <bits/stdc++.h>
using namespace std;
long long int binary_exp(long long int a, long long int n) {
  long long int i = 1;
  while (n > 0) {
    if (n % 2 == 1) i = (i * a) % 1000000007;
    a = (a * a) % 1000000007;
    n /= 2;
  }
  return i;
}
long long int IsPrime(long long int n) {
  if (n == 0 || n == 1) return n;
  if (n % 2 == 0) return (long long int)2;
  if (n % 3 == 0)
    return (long long int)3;
  else {
    for (long long int i = 5; i * i <= n; i += 6) {
      if (n % i == 0) return i;
      if (n % (i + 2) == 0) return (i + 2);
    }
    return n;
  }
}
void solve() {
  int n, i, j, k, a, b, mex = 1, ans = 0;
  cin >> n;
  int ind[n + 1];
  bool vis[n + 1];
  memset(vis, false, sizeof(vis));
  for (i = 1; i <= n; i++) {
    cin >> k;
    ind[k] = i;
  }
  for (i = 1; i <= n; i++) {
    cin >> k;
    vis[ind[k]] = true;
    while (mex <= n && vis[mex]) mex++;
    if (ind[k] > mex) ans++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1;
  while (t--) solve();
}
