#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, long long p, long long md) {
  if (p == 0) return 1;
  if (p % 2 == 1) {
    return ((b % md) * bigmod(b, p - 1, md)) % md;
  } else {
    long long y = bigmod(b, p / 2, md);
    return (y * y) % md;
  }
}
long long in[200005];
long long out[200005];
int main() {
  int n;
  cin >> n;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    int id;
    cin >> id;
    q.push(id);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int id;
    cin >> id;
    while (q.size()) {
      if (in[q.front()])
        q.pop();
      else
        break;
    }
    if (id == q.front())
      q.pop();
    else if (q.size()) {
      in[id] = 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
