#include <bits/stdc++.h>
using namespace std;

int n,a[100003],b[100003];
string s1,s2,s;
void fun(int n){
    cout<< "a -> ";
    for(int i=0;i<n;i++){
        cout<< a[i] << " ";
    }
    cout<< endl;
    cout<< "b -> ";
    for(int i=0;i<n;i++) cout<< b[i] << " ";
    cout<< endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>> n;
    for(int i=0;i<n;i++){
        cin>> a[i];
    }
    for(int i=0;i<n;i++){
        cin>> b[i];
    }
    int t=0,br=0;;
    while(t<n){
        bool f=false;
        for(int i=0;i<n;i++){
            if(b[t]==a[i]){
                a[i]=-1;
                b[t]=-1;
                //fun(n);
                f=true;
                for(int j=t+1;j<n;j++){
                    if(b[j]==a[i+j-t]){
                        b[j]=-1;
                        a[i+j-t]=-1;
                        t++;
                    }else{
                        break;
                    }
                    //fun(n);
                }
            }
            if(f) break;
        }
        //cout<< endl;
        //fun(n);
        //cout<< endl;
        br++;
        t++;
    }
    cout<< br+2;







    return 0;
}

