#include <iostream>
using namespace std;
int a[1000], b[1000], ind[1000];
int main () {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        ind[b[i]] = i;
    }
    int curr = -1, ans = 1;
    for (int i = 1; i <= n; i++) {
        if (curr == -1) {
            curr = ind[a[i]] + 1;
        } else {
            if (a[i] == b[curr]) {
                curr++;
            } else {
                curr = -1;
                i--;
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}
