#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int main(){ int n, m; while(cin >> n >> m){ string S, T; cin >> S >> T; vector dp(n+1, vi(m+1, 10000)); dp[0][0] = 0; rep(i, n + 1)rep(j, m + 1){ int val = dp[i][j]; if(i < n&&j < m&&S[i] == T[j]) smin(dp[i + 1][j + 1], val); if(i < n)smin(dp[i + 1][j], val + 1); if(j < m)smin(dp[i][j + 1], val + 1); if(i < n&&j < m)smin(dp[i + 1][j + 1], val + 1); } cout << dp[n][m] << endl; } }