#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // ascending order #define vsort(v) sort(v.begin(), v.end()) // descending order #define vsort_r(v) sort(v.begin(), v.end(), greater()) #define vunique(v) unique(v.begin(), v.end()) #define mp make_pair #define ts(x) to_string(x) #define rep(i, a, b) for(int i = (int)a; i < (int)b; i++) #define repm(i, a, b) for(int i = (int)a; i > (int)b; i--) typedef long long ll; typedef pair P; const ll INF = 1e18; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; string s, t; cin >> s >> t; ll dp[n + 1][m + 1]; rep(i, 0, n + 1) rep(j, 0 , m + 1) dp[i][j] = INF; dp[0][0] = 0; rep(i, -1, n) { rep(j, -1, m) { if(i == -1 && j == -1) continue; if(s[i] != t[j]) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1); else dp[i + 1][j + 1] = min(dp[i][j], dp[i + 1][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; }