#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int vis[N] = {-1};
int main() {
  int n, c = 0;
  cin >> n;
  vector<int> a, v;
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    a.push_back(w);
    vis[w] = 0;
  }
  int j = 0;
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    v.push_back(w);
  }
  for (int i = 0; i < n; i++) {
    if (a[j] == v[i])
      j++, vis[v[i]] = 1;
    else {
      if (vis[a[j]] == 0)
        c++, vis[v[i]] = 1;
      else
        j++, i--;
    }
  }
  cout << c;
}
