import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n, m = map(int, input().split()) s = input().rstrip() t = input().rstrip() dp = [[0]*(m+1) for _ in range(n+1)] for i in range(n): dp[i+1][0] = dp[i][0]+1 for i in range(m): dp[0][i+1] = dp[0][i] + 1 for i in range(n): for j in range(m): if s[i] == t[j]: dp[i+1][j+1] = min(dp[i+1][j]+1, dp[i][j+1]+1, dp[i][j]) else: dp[i+1][j+1] = min(dp[i+1][j]+1, dp[i][j+1]+1, dp[i][j]+1) print(dp[n][m])