nm = input().rstrip().split() n, m = int(nm[0]), int(nm[1]) S = input().rstrip() T = input().rstrip() dp = [[0 for j in range(n+1)] for i in range(m+1)] for i in range(m+1): dp[i][0] = i for j in range(n+1): dp[0][j] = j # dp[i][j]: Sのj文字目までをTのi文字目までに変換するための最小操作回数 for i in range(m): for j in range(n): if T[i] == S[j]: x = 0 else: x = 1 dp[i+1][j+1] = min(dp[i][j+1]+1, dp[i+1][j]+1, dp[i][j]+x) print(dp[m][n])