#include <bits/stdc++.h>
using namespace std;
int tree[302000];
pair<int, int> a[302000];
int n, b[302000], pos[302000], ans(0);
void ins(int t, int val) {
  for (int i = t; i <= n; i += (i) & (-i)) tree[i] += val;
}
int ask(int t) {
  int ret = 0;
  for (int i = t; i; i -= (i) & (-i)) ret += tree[i];
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i].first);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i].second);
  for (int i = 1; i <= n; ++i) pos[a[i].second] = i;
  for (int i = 1; i <= n; ++i) b[i] = pos[a[i].first];
  memset(tree, 0, sizeof(tree));
  for (int i = 1; i <= n; ++i) {
    if (b[i] > b[i + 1]) {
      ans = n - i;
      break;
    }
  }
  cout << ans << endl;
}
