#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
inline long long getPow(long long a, long long b) {
  long long res = 1ll, tp = a;
  while (b) {
    if (b & 1ll) {
      res *= tp;
    }
    tp *= tp;
    b >>= 1ll;
  }
  return res;
}
long long vec_mult(long long x1, long long y1, long long x2, long long y2,
                   long long x3, long long y3) {
  return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
}
void ok() {
  puts("YES");
  exit(0);
}
void no() {
  puts("NO");
  exit(0);
}
inline long long nxt() {
  long long x;
  cin >> x;
  return x;
}
const long long N = 2e5 + 10, inf = 2e18;
long long xx[] = {1, -1, 0, 0};
long long yy[] = {0, 0, 1, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n = nxt();
  vector<long long> mas(n);
  for (int i = 0; i < n; i++) {
    mas[i] = nxt() - 1;
  }
  vector<long long> arr(n);
  vector<long long> used(n);
  for (int i = 0; i < n; i++) {
    arr[i] = nxt() - 1;
    used[arr[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    mas[i] = used[mas[i]];
  }
  long long cur = mas[0];
  long long ct = 1;
  for (int i = 1; i < n; i++) {
    if (cur < mas[i]) {
      ct++;
      cur = mas[i];
    } else
      break;
  }
  cout << n - ct;
  return 0;
}
