#include using namespace std; int N, M; string S, T; vector> memo; int book(int s, int t) { if (s == 0 && t == 0) return 0; if (s < 0 || t < 0) return 1e5; if (memo[s][t] != -1) return memo[s][t]; int& ret = memo[s][t]; ret = 1e5; ret = min(ret, book(s - 1, t - 1) + (S[s - 1] != T[t - 1])); ret = min(ret, book(s - 1, t) + 1); ret = min(ret, book(s, t - 1) + 1); return ret; } int main() { cin >> N >> M >> S >> T; memo.resize(N + 1); for (int i = 0; i < N + 1; i++) memo[i].resize(M + 1, -1); cout << book(N, M) << endl; }