#include #define rep(i, n) for(ll i=0; i=e; i--) #define reps(i, s, e) for(ll i=s; i<=e; i++) #define ll long long #define inf 1e18 #define all(v) v.begin(),v.end() #define vsort(v) sort(v.begin(), v.end()) #define vsortr(v) sort(v.begin(), v.end(), greater()) #define sz(x) x.size() #define ceil(a, b) (a+b-1)/b #define ok cout << "ok" << endl; #define sp << " " << using namespace std; template inline bool chmax(T &a, T b){ if(a inline bool chmin(T &a, T b){ if(b T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); } template T lcm(T a, T b){ return a*(b/gcd(a, b)); } template void vdebug(vector v){ for(auto vv : v){ cout << vv << " "; } cout << endl; } template void adebug(T arr[], ll n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; } void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; } void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; } ll keta(ll num){ ll k=0; while(num>0){ num/=10; k++; } return k; } int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n, m; ll dp[1010][1010]; string s, t; cin >> n >> m >> s >> t; rep(i, 1010){ rep(j, 1010){ dp[i][j] = inf; } } dp[0][0] = 0; reps(i, -1, n){ reps(j, -1, m){ if(i == -1 && j == -1) continue; if(i >= 0 && j >= 0){ if(s[i] == t[j]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1); } if(i >= 0) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1] + 1); if(j >= 0) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j] + 1); } } cout << dp[n][m] << endl; return 0; }