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