#include <iostream>

using namespace std;

int findInArr2(int cell, int arr2[], int n) {
    for ( int i = 0; i < n; i ++ ) {
        if ( cell == arr2[i] ) return i;
    }
    return -1;
}

int readBuff(int index, int arr1[], int arr2[], int n) {
    int i = findInArr2(arr1[index], arr2, n);
    while (arr1[index] == arr2[i]) {
        index ++;
        i ++;
        if ( i + index == 2*n ) break;
    }
    return index;
}

int main () {

    int n;
    cin >> n;
    int arr1[n], arr2[n];
    for ( int i = 0; i < n; i ++ ) {
        cin >> arr1[i];
    }
    for ( int i = 0; i < n; i ++ ) {
        cin >> arr2[i];
    }
    //write a function that detects simular peaces in each array
    int index = 0, times = 0;
    while (index < n ) {
        index = readBuff(index, arr1, arr2, n);
        times ++;
    }
    cout << times << endl;
    return 0;
}
