#include <bits/stdc++.h> #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<int,long double> pr; typedef pair<pr,int> ppr; typedef priority_queue<pr,vector<pr>,greater<pr> > PQ; typedef vector<pr> Vpr; typedef vector<LL> VI; typedef complex<LL> cld; typedef vector<cld> Vcld; typedef map<pr,int> 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; }