#include<iostream>
using namespace std;

int n ;
int row1[100000], row2[100000];

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n ;
    for(int i = 0 ; i < n ; i ++){
        cin >> row1 [i];
    }
    for(int i = 0 ; i < n ; i ++){
        cin >> row2 [i];
    }

    bool flag = false ;
    int brSuvpadashti = 0, brSuvpadashtiChasti = 0, ans = n;
    for(int i = 0 ; i < n - 1 ; i ++){
        for(int j = 0 ; j < n - 1 ; j ++){
            if(flag){
                //cout << "zele" << endl ;
                //cout << "AlaBala: " << row1 [i] << " " << row2 [i] << endl ;
                if(row1 [i] == row2 [j]){
                    brSuvpadashti ++ ;
                    i ++ ;
                }else{
                    brSuvpadashtiChasti ++ ;
                    flag = false ;
                    i -- ;
                    break ;
                }
            }
            else{
                //cout << "kufte" << endl ;
                //cout << "Nizove: " << row1 [i] << " " << row1[i + 1] << " " << row2 [j] << " " << row2 [j + 1] << endl ;
                if(row1 [i] == row2 [j] and row1 [i + 1] == row2 [j + 1]){
                    //cout << "Kartof: " << row1 [i] << " " << row1[i + 1] << " " << row2 [j] << " " << row2 [j + 1] << endl ;
                    flag = true ;
                    brSuvpadashti += 2;
                    i += 2;
                    j ++ ;
                }
            }
        }
    }
    if(flag){
        brSuvpadashtiChasti ++ ;
    }

    //cout << brSuvpadashti << " " << brSuvpadashtiChasti << endl ;

    ans = ans - brSuvpadashti + brSuvpadashtiChasti;

    cout << ans << endl ;

    return 0;
}
/*
8
1 2 5 6 7 4 3 8
1 2 3 4 5 6 7 8

*/
