#include <bits/stdc++.h>
using namespace std;
template <class T, class OP>
class SegmentTreeT {
  T *a[32];
  int n, depth;
  bool up_to_date;
  OP op;

 public:
  SegmentTreeT(int size) : n(size), up_to_date(false), op(OP()) {
    depth = 0;
    for (int x = n; x; x >>= 1) ++depth;
    assert(depth < 31);
    a[0] = new T[n * 2]();
    for (int i = 1, l = n; i <= depth; ++i) {
      a[i] = a[i - 1] + l;
      l /= 2;
    }
  }
  ~SegmentTreeT() { delete[] a[0]; }
  void build() {
    int l = n;
    for (int d = 1; d <= depth; ++d) {
      l = l / 2;
      for (int i = 0; i < l; ++i)
        a[d][i] = merge(a[d - 1][2 * i], a[d - 1][2 * i + 1]);
    }
    up_to_date = true;
  }
  void build(const T &Val) {
    for (int i = 0; i < n; ++i) a[0][i] = Val;
    build();
  }
  void update(int i, const T &v) {
    assert(0 <= i && i < n);
    a[0][i] = v;
    for (int d = 1; i / 2 < (n >> d); ++d) {
      i /= 2;
      a[d][i] = merge(a[d - 1][2 * i], a[d - 1][2 * i + 1]);
    }
  }
  T &operator[](int i) {
    assert(0 <= i && i < n);
    assert(!up_to_date);
    return a[0][i];
  }
  const T &operator()(int i) const {
    assert(0 <= i && i < n);
    return a[0][i];
  }
  T brute(int l, int r) {
    assert(l <= r && 0 <= l && r < n);
    T res = a[0][l];
    for (int i = l + 1; i <= r; ++i) res = merge(res, a[0][i]);
    return res;
  }
  T merge(const T &x, const T &y) { return op(x, y); }
  T get(int l, int r) {
    assert(l <= r && 0 <= l && r < n);
    assert(up_to_date);
    return get(l, r, 0);
  }

 private:
  T get(int l, int r, int d) {
    if (l == r) return a[d][l];
    T res;
    bool valid = false;
    if ((l + 1) / 2 <= (r - 1) / 2) {
      res = get((l + 1) / 2, (r - 1) / 2, d + 1);
      valid = true;
    }
    if (l & 1) {
      if (valid)
        res = merge(res, a[d][l]);
      else
        res = a[d][l];
      valid = true;
    }
    if ((r & 1) == 0) {
      if (valid)
        res = merge(res, a[d][r]);
      else
        res = a[d][r];
      valid = true;
    }
    assert(valid);
    return res;
  }
};
template <class T>
struct Sum {
  T operator()(T a, T b) { return (a + b); }
};
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int o[100111];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    o[a[i]] = i;
  }
  int ans = 0;
  SegmentTreeT<int, Sum<int>> st(n);
  st.build();
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    x = o[x];
    int nc = st.get(0, x);
    if (nc != x) ++ans;
    st.update(x, 1);
  }
  cout << ans << "\n";
  return 0;
}
