#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define MAX 1111 int N,M; string S, T; int dp[MAX][MAX]; signed main() { cin >> N >> M >> S >> T; REP(i,M+1) dp[S.size()][i] = M-i; RREP(i,N) { RREP(j,M) { dp[i][j] = min(dp[i+1][j+1] + (S[i] != T[j]), dp[i+1][j] + 1); dp[i][j] = min(dp[i][j], dp[i][j+1] + 1); } } cout << dp[0][0] << endl; return 0; }