from functools import lru_cache @lru_cache(maxsize=10000) def f(x, y): if x == 0: return y if y == 0: return x if S[x - 1] == T[y - 1]: return f(x - 1, y - 1) else: return min(f(x - 1, y), f(x, y - 1), f(x - 1, y - 1)) + 1 n, m = map(int, input().split()) S = input() T = input() print(f(n, m))