#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) using ll = long long; const ll INF = 1LL<<60; template inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} int main() { int n, m; cin >> n >> m; string S, T; cin >> S >> T; vector> dp(S.size()+1, vector(T.size()+1, INF)); dp[0][0] = 0; rep(i, S.size()) rep(j, T.size()) { if (S[i] == T[j]) chmin(dp[i+1][j+1], dp[i][j]); // copy chmin(dp[i+1][j+1], dp[i][j] + 1); // replace chmin(dp[i+1][j+1], dp[i][j+1] + 1); // delete chmin(dp[i+1][j+1], dp[i+1][j] + 1); // insert } cout << dp[S.size()][T.size()] << endl; return 0; }