import numpy as np N, M = map(int, input().split()) S = np.array(list(input())) T = np.array(list(input())) min1 = np.frompyfunc(lambda x, y: min(x, y) + 1, 2, 1) eq = (S[:, None] == T[None, :]) dp = np.zeros((N + 1, M + 1), dtype=int) dp[0] = np.arange(M + 1) dp[:, 0] = np.arange(N + 1) for i in range(N): dp[i + 1, 1:] = np.minimum(dp[i, 1:], dp[i, :-1] - eq[i]) dp[i + 1] = min1.accumulate(dp[i + 1], dtype=np.int64) print(dp[N, M])