#include <bits/stdc++.h>
using namespace std;
int inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 223372036854775807;
int A[200005] = {};
int B[200005] = {};
int pos[200005] = {};
int main() {
  int a;
  while (cin >> a) {
    for (int i = 1; i <= a; i++) cin >> A[i];
    for (int i = 1; i <= a; i++) {
      cin >> B[i];
      pos[B[i]] = i;
    }
    int ans = 0;
    for (int i = 2; i <= a; i++) {
      if (pos[A[i]] < pos[A[i - 1]]) {
        ans = a - i + 1;
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
