#include<bits/stdc++.h>
using namespace std;
int n;
int a[10004],b[10004];
int dp[1004][1004];
int solve(int it1,int it2){
    if(it1>=n||it2>=n){
        return 10004;
    }
    else if(dp[it1][it2]!=0){
        return dp[it1][it2];
    }
    else{
        if(a[it1]!=b[it2]){
            dp[it1][it2]=min(solve(it1+1,it2),solve(it1,it2+1))+1;
        }
        else{
            int p=1;
            int x=it1+1,y=it2+1;
            while(a[x]==b[y]){
                p++;
                x++;
                y++;
            }
            dp[it1][it2]=p+solve(x,y);
        }
    }
    return dp[it1][it2];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp,0,sizeof(dp));
//freopen("test.txt","r",stdin);
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<n;i++){
    cin>>b[i];
}
cout<<solve(0,0)-10004;
return 0;
}
