#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= 0.00000000000001 ? 0 : (a > b) ? 1 : -1;
}
vector<int> v1, v2, v;
int vis[200000 + 9];
int main() {
  int n, id1, id2, id, i, ch, l;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ch;
    v1.push_back(ch);
  }
  for (i = 0; i < n; i++) {
    cin >> ch;
    v2.push_back(ch);
    vis[ch] = i;
  }
  for (i = 0; i < n; i++) {
    v.push_back(vis[v1[i]]);
  }
  id = n - 1;
  for (i = 0; i < n; i++) {
    if (v[i] > v[i + 1]) {
      id = i;
      break;
    }
  }
  cout << (n - 1) - id << endl;
}
