#include using namespace std; #define llong long long int #define ldouble long double #define fore(i, x) for (auto &i : n) #define rep(i, n) for (int i = 0; i < n; ++i) #define repr(i, n) for (int i = n; i >= 0; --i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int mod = 1000000000 + 7; const static int inf = INT_MAX / 2; const static llong INF = LLONG_MAX / 2; const static double eps = 1e-6; const static int dx[] = {1, 0, -1, 0}; const static int dy[] = {0, 1, 0, -1}; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1;} return 0;} template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0;} int levenshtein_distance(string S1, string S2) { int l1 = S1.size(), l2 = S2.size(); int dp[l1 + 1][l2 + 1]; rep(i, l1 + 1) dp[i][0] = i; rep(i, l2 + 1) dp[0][i] = i; for (int i = 1; i < l1 + 1; ++i) { for (int j = 1; j < l2 + 1; ++j) { int alpha = (S1[i - 1] == S2[j - 1]) ? 0 : 1; dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + alpha)); } } return dp[l1][l2]; } signed main (int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; string s1, s2; cin >> s1 >> s2; cout << levenshtein_distance(s1, s2) << endl; return 0; }