#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn];
bool c[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int cnt = 0;
  int l = 0, k = 0;
  while (l < n && k < n) {
    if (a[l] != b[k]) {
      c[b[k]] = 1;
      cnt++;
      k++;
    } else {
      l++;
      k++;
    }
    while (c[a[l]]) l++;
  }
  cout << cnt << endl;
}
