#include <bits/stdc++.h>
static const int INF = std::numeric_limits<int>::max();
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    std::cin >> b[i];
  }
  int res = 0;
  if (a == b) {
    res = 0;
  } else {
    int off;
    for (off = 0; a[off] == b[off]; ++off)
      ;
    int len = 0;
    for (int i = off; i < n; ++i) {
      if (a[off] == b[i]) {
        int j, k;
        for (j = 0, k = 0; i + k < n;) {
          if (a[off + j] != b[i + k]) {
            ++k;
          } else {
            ++j;
            ++k;
            ++len;
          }
        }
        break;
      }
    }
    res = n - off - len;
  }
  std::cout << res << std::endl;
}
