#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int dp[1001][1001];

int levenshteinDisntace(string s, string t) {
    rep (i, s.length() + 1) {
        dp[i][0] = i;
    }

    rep (i, t.length() + 1) {
        dp[0][i] = i;
    }

    rep2 (i, 1, s.length() + 1) {
        rep2 (j, 1, t.length() + 1) {
            int cost;

            if (s[i - 1] == t[j - 1]) {
                cost = 0;
            } else {
                cost = 1;
            }

            dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost});
        }
    }

    return dp[s.length()][t.length()];
}


int main() {
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    cout << levenshteinDisntace(s, t) << endl;
}