#include <bits/stdc++.h>
const int mx = 2e5 + 10;
using namespace std;
int a[mx], b[mx], vis[mx];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    vis[b[i]] = i;
  }
  int tmp = -1, ans = n;
  for (int i = 0; i < n; i++) {
    if (vis[a[i]] > tmp) {
      ans--;
      tmp = vis[a[i]];
    } else {
      break;
    }
  }
  cout << ans << endl;
}
