slen, tlen = map(int, input().split()) s = input() t = input() dp = [[None] * tlen for _ in range(slen)] def dfs(a=slen - 1, b=tlen - 1): if a == 0: return b if b == 0: return a if dp[a][b] is not None: return dp[a][b] r = min( dfs(a - 1, b) + 1, dfs(a, b - 1) + 1, dfs(a - 1, b - 1) + (s[a] != t[b]), ) dp[a][b] = r return r print(dfs())