#include using namespace std; const int MAX_N = 1010; const int MAX_M = 1010; const int INF = (1 << 28); int dp[MAX_N][MAX_M]; int main() { int n, m; string s, t; cin >> n >> m; cin >> s >> t; fill((int* )dp, (int* )(dp + MAX_N), INF); dp[0][0] = 0; dp[n][0] = 0; dp[0][m] = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i - 1 >= 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1); } if (j - 1 >= 0) { dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1); } if (i - 1 >= 0 && j - 1 >= 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (s[i - 1] == t[j - 1] ? 0 : 1)); } } } cout << dp[n][m] << endl; return 0; }