#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5 + 5);
bool was[N];
int p1[N], p2[N], res, pos[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", p1 + i);
    pos[p1[i]] = i + 1;
  }
  for (int i = 0; i < n; i++) scanf("%d", p2 + i);
  int j = 0;
  for (int i = 0; i < n; i++) {
    was[p2[i]] = true;
    if (p1[j] != p2[i]) {
      res = max(res, n - pos[p2[i]] + 1);
    } else {
      while (was[p1[j]]) j++;
    }
  }
  cout << res << endl;
  return 0;
}
