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