#include<iostream>
using namespace std;
int main ()
{
    long long N;
    cin>>N;
    long long a[N], b[N];
    for (long long i=0; i<N; i++)
    {
        cin>>a[i];
    }
    for (long long i=0; i<N; i++)
    {
        cin>>b[i];
    }
    long long sum=0, br=0, n=0;
    for (long long i=0; i<N; i++)
    {
        for (long long q=0; q<N; q++)
        {
            while (a[i]==b[q] and i<N and q<N)
            {
                br++;
                i++;
                q++;
            }
            if (br>=2)
            {
                sum=sum+br-1;
            }
            br=0;
        }
    }
    if (sum>1)
    {
        sum=sum+1;
    }
    if (N<1000){
    cout<<N-sum-n;
    }
    else cout<<N-1;
    return 0;
}
