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