#include <bits/stdc++.h>
using namespace std;
int fs[100005];
int main() {
  queue<int> s1, s2;
  int n, p, q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    s1.push(p);
  }
  for (int i = 0; i < n; i++) {
    cin >> q;
    s2.push(q);
  }
  int cnt = 0;
  while (!s1.empty()) {
    int x = s1.front();
    s1.pop();
    if (fs[x] == 1) continue;
    while (s2.empty() != 1 && s2.front() != x) {
      cnt++;
      int m = s2.front();
      fs[m] = 1;
      s2.pop();
    }
    if (s2.front() == x) {
      fs[x] = 1;
      s2.pop();
    }
  }
  cout << cnt << endl;
}
