#include #include #include using namespace std; int main() { int n, m; cin >> n >> m; string s, t; cin >> s >> t; vector> dp(n + 1, vector(m, 1001)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j++) { if (j == 0) { if (s[i - 1] == t[j]) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = dp[i - 1][j] + 1; } } else { if (s[i - 1] == t[j]) { dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j] + 1, dp[i][j - 1] + 1)); } else { dp[i][j] = min(dp[i - 1][j - 1] + 1, min(dp[i - 1][j] + 1, dp[i][j - 1] + 1)); } } } } cout << dp[n][m - 1] << endl; }