#include #include using namespace std; int const MAX = 1100; int const INF = 1<<29; int N, M; string S, T; int dp[MAX][MAX]; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) int main() { cin >> N >> M >> S >> T; fill(dp[0], dp[0]+MAX*MAX, INF); S += '?', T += '?'; dp[0][0] = 0; rep(i, N+1) rep(j, M+1) { if(S[i] == T[j]) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); } else { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1); dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1); dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1); } } cout << dp[N][M] << endl; return 0; }