#include <bits/stdc++.h>
using namespace std;
long long n, p, w, d;
int a[100005];
int b[100005];
int c[100005];
const int maxn = 100005;
int stmin[maxn][20], stmax[maxn][20];
void InitSt() {
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      stmin[i][j] = min(stmin[i][j - 1], stmin[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int query(int l, int r) {
  int x = (int)(log(double(r - l + 1)) / log(2.0));
  return min(stmin[l][x], stmin[r - (1 << x) + 1][x]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    stmin[i][0] = c[b[i]];
  }
  InitSt();
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    if (stmin[i][0] > query(i + 1, n)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
