#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, value;
};
void solve();
int main() {
  int times = 1;
  for (int i = 1; i <= times; i++) {
    solve();
    cout << '\n';
  }
  return 0;
}
const int n = 2e5;
vector<edge> tree[n + 50];
int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;
void solve() {
  cin >> a;
  int pos[a + 50];
  for (int i = 0; i < a; i++) cin >> arr1[i];
  for (int i = 0; i < a; i++) cin >> arr2[i];
  int index = 0, cnt = 0;
  bool choose[a + 50];
  memset(choose, 0, sizeof(choose));
  ;
  for (int i = 0; i < a; i++) {
    if (arr2[i] != arr1[index]) {
      cnt++;
    } else {
      index++;
      while (choose[arr1[index]]) {
        index++;
      }
      if (index >= a) break;
    }
    choose[arr2[i]] = true;
  }
  cout << cnt;
}
