#include template inline bool chmax(T &a, const T &b){if(a < b){a = b; return true;}return false;} using namespace std; using ll = long long; int main(){ int N, M; cin >> N >> M; string S, T; cin >> S >> T; vector> dp(N + 1, vector(M + 1, 0)); for(int i = 0; i < N; i++)dp[i + 1][0] = dp[i + 1][0] + 1; for(int i = 0; i < M; i++)dp[0][i + 1] = dp[0][i] + 1; for(int i = 0; i < N; i++)for(int j = 0; j < M; j++){ dp[i + 1][j + 1] = min(dp[i][j] + (S[i] == T[j] ? 0: 1), min(dp[i][j + 1] + 1, dp[i + 1][j] + 1)); } cout << dp[N][M] << endl; }