#include<bits/stdc++.h>
#define MAXN 1004
using namespace std;
int n,a[MAXN],b[MAXN];
int dp[MAXN][MAXN];
int solve(int ita,int itb){
    if(ita>=n||itb>=n){
        return MAXN;
    }
    else if(dp[ita][itb]!=0){
        return dp[ita][itb];
    }
    else{
        if(a[ita]==b[itb]){
            int x=ita,y=itb;
            while(true){
                if(x>=n||y>=n){
                    break;
                }
                else if(a[x]!=b[y]){
                    break;
                }
                else{
                    x++;
                    y++;
                }
            }
            dp[ita][itb]=1;
            int kr=solve(x,y);
            if(kr<MAXN){
                dp[ita][itb]+=kr;
            }
        }else{
            int tr=solve(ita+1,itb)+1;
            int pr=solve(ita,itb+1);
            dp[ita][itb]=min(tr,pr);
        }
    }
    return dp[ita][itb];
}
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;
}

