#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int dp[1001][1001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m; string s, t; cin >> n >> m; cin >> s; cin >> t; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { dp[i][j] = 1e9; } } for (int i = 1; i <= n; i++) { dp[i][0] = i; } for (int j = 1; j <= m; j++) { dp[0][j] = j; } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i - 1] == t[j - 1]) { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]); } else { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1); dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1); dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1); } } } cout << dp[n][m] << '\n'; return 0; }