#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int a[N], b[N];
int t[N], pos[N];
bool vis[N];
int main() {
  memset(vis, 0, sizeof(vis));
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  for (int i = 1; i <= n; ++i) t[b[i]] = i;
  for (int i = 1; i <= n; ++i) pos[i] = t[a[i]];
  int ans = 0;
  int num = 0;
  for (int i = 1; i <= n; ++i) {
    if (pos[i] < num) {
      ans = n + 1 - i;
      break;
    }
    num = pos[i];
  }
  printf("%d\n", ans);
  return 0;
}
