#include<bits/stdc++.h>
#define MAXN 10004
using namespace std;
int n,a[MAXN],b[MAXN];
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(it2==n-1){
        return dp[it1][it2]=n-it1;
    }

    else{
        if(a[it1]!=b[it2]){
            int tr=solve(it1+1,it2);
            int pr=solve(it1,it2+1);
            if(tr<pr){
                dp[it1][it2]+=tr+1;
            }else{
                dp[it1][it2]+=pr+1;
            }
        }
        else{
            int x=it1+1,y=it2+1;
            while(true){
                if(x>=n||y>=n){
                    break;
                }
                else if(a[x]!=b[y]){
                    break;
                }
                else{
                    x++;
                    y++;
                }
            }
            int kr=solve(x,y);
            dp[it1][it2]=1;
            if(kr<10004){
                dp[it1][it2]+=kr;
            }
        }
    }
    return dp[it1][it2];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("test.txt","r",stdin);
memset(dp,0,sizeof(dp));
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);
return 0;
}