#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; const int INF = 1 << 30; const int MOD = 1e9 + 7; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { int n, m; string S, T; cin >> n >> m >> S >> T; vector> dp(1001, vector(1001, INF)); dp[0][0] = 0; for (int i = 0; i < S.size(); i++) { for (int j = 0; j < T.size(); j++) { if (S[i] == T[j]) { dp[i + 1][j + 1] = min({ dp[i + 1][j + 1], dp[i][j], dp[i][j + 1] + 1, dp[i + 1][j] + 1 }); } else { dp[i + 1][j + 1] = min({ dp[i + 1][j + 1], dp[i][j] + 1, dp[i][j + 1] + 1, dp[i + 1][j] + 1 }); } } } cout << dp[S.size()][T.size()] << endl; return 0; }