#include #include #include using namespace std; typedef long long ll; int main() { int dp[1001][1001], l1, l2, cost; string s1, s2; cin >> l1 >> l2; cin >> s1; cin >> s2; for(int i = 0; i <= l1; i++) dp[i][0] = i; for(int i = 0; i <= l2; i++) dp[0][i] = i; for(int i = 1; i <= l1; i++) { for(int j = 1; j <= l2; j++) { if (s1[i - 1] == s2[j - 1]) cost = 0; else cost = 1; dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost)); } } cout << dp[l1][l2] << endl; return 0; }