#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int c[n], cn[n];
    int perm[n + 1];
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        if(i != 0) {
            perm[c[i - 1]] = c[i];
        }
    }
    perm[c[n - 1]] = -1;
    int cut = n;
    for(int i = 0; i < n; i++) {
        cin >> cn[i];
        if(i != 0)
            if(perm[cn[i - 1]] == cn[i]) cut--;

    }

    cout << cut << endl;



    return 0;
}

