#include #include using namespace std; using ll = long long; using vll = vector; using vvll = vector; using vpl = vector>; using pll = pair; #define rep(i, k, n) for(ll i = k; i < n; i++) #define pb push_back #define mp make_pair template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll n, m; string s, t; const ll INF = 10000000000; vvll dp(1010, vll(1010, INF)); int main(){ cin >> n >> m >> s >> t; dp[0][0] = 0; rep(i, 0, n){ rep(j, 0, m){ if(s[i] == t[j]) chmin(dp[i+1][j+1], dp[i][j]); //変更 chmin(dp[i+1][j+1], dp[i][j] + 1); //削除 chmin(dp[i+1][j+1], dp[i][j+1] + 1); //挿入 chmin(dp[i+1][j+1], dp[i+1][j] + 1); } } cout << dp[n][m] << endl; }