#include #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,b) FOR(i,0,b) #define F first #define S second #define PB(a) push_back(a) #define BE(c) c.begin(),c.end() using namespace std; typedef long long LL; typedef pair pr; typedef pair ppr; typedef priority_queue,greater > PQ; typedef vector Vpr; typedef vector VI; typedef complex cld; typedef vector Vcld; typedef map MP; const int SIZE=100010; const LL INF=1<<28; string a,b; int DP[1001][1001]; int solve(int x,int y){ if(DP[x+1][y+1]) return DP[x+1][y+1]; if(x!=-1||y!=-1){ if(x==-1) return DP[x+1][y+1]=solve(x,y-1)+1; if(y==-1) return DP[x+1][y+1]=solve(x-1,y)+1; if(a[x]==b[y]) return DP[x+1][y+1]=solve(x-1,y-1); return DP[x+1][y+1]=min(solve(x,y-1),min(solve(x-1,y-1),solve(x-1,y)))+1; } return 0; } int main(){ int x,y; cin >> x>>y; cin >> a >> b; cout << solve(a.size(),b.size()) << endl; return 0; }