#include <bits/stdc++.h>
using namespace std;
int tree[500000];
int a[100000], pos[100001];
void update(int node, int l, int r, int pos, int u) {
  if (l == r) {
    tree[node] += u;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    update(2 * node, l, mid, pos, u);
  else
    update(2 * node + 1, mid + 1, r, pos, u);
  tree[node] = tree[2 * node] + tree[2 * node + 1];
}
int query(int node, int l, int r, int ql, int qr) {
  if (ql > r || qr < l) return 0;
  if (ql <= l && qr >= r) return tree[node];
  int mid = (l + r) / 2;
  return query(2 * node, l, mid, ql, qr) +
         query(2 * node + 1, mid + 1, r, ql, qr);
}
int main() {
  int i, j, k;
  int n, res = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    pos[j] = i;
  }
  for (i = 0; i < n; i++) {
    if (query(1, 0, n, pos[a[i]] + 1, n)) res++;
    update(1, 0, n, pos[a[i]], 1);
  }
  printf("%d", res);
}
