#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  while (cin >> n) {
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      cin >> b[i];
    }
    reverse(b.begin(), b.end());
    stack<int> s;
    for (int i = 0; i < n; ++i) {
      s.push(b[i]);
    }
    vector<bool> vis(n, 0);
    int i = 0, c = 0;
    while (!s.empty() && i < n) {
      if (vis[a[i]]) {
        ++i;
      } else {
        int now = s.top();
        s.pop();
        vis[now] = 1;
        if (a[i] == now) {
          ++i;
        } else {
          ++c;
        }
      }
    }
    cout << c << '\n';
  }
  return 0;
}
