#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long power(long long first, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * first;
    first = first * first;
    n = n / 2;
  }
  return result;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (long long &first : a) cin >> first;
  for (long long &first : b) cin >> first;
  long long count = 0;
  map<long long, long long> m;
  while (!a.empty() && !b.empty()) {
    long long first = a[a.size() - 1], second = b[b.size() - 1];
    if (first != second && !m[second]) {
      m[first]++;
      count++;
      a.pop_back();
    } else if (first != second && m[second])
      b.pop_back();
    else {
      a.pop_back();
      b.pop_back();
    }
  }
  cout << count;
}
