#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; ll INF = 1e8; int main(){ int N, M; cin >> N >> M; string S, T; cin >> S >> T; vector> dp(N + 1, vector(M + 1, INF)); dp[0][0] = 0; for(int i = 0; i < N; i++)dp[i + 1][0] = dp[i][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++){ if(S[i] == T[j])dp[i + 1][j + 1] = min(dp[i][j], min(dp[i][j + 1] + 1, dp[i + 1][j] + 1)); else dp[i + 1][j + 1] = min(dp[i][j] + 1, min(dp[i][j + 1] + 1, dp[i + 1][j] + 1)); } cout << dp[N][M] << endl; }