n,m = map(int,input().split()) S = input() T = input() DP = [[0]*(m+1) for i in range(n+1)] DP[0] = [i for i in range(m+1)] for i in range(n): DP[i+1][0] = i+1 for j in range(m): if S[i] == T[j]: DP[i+1][j+1] = DP[i][j] else: DP[i+1][j+1] = min(DP[i][j],DP[i+1][j],DP[i][j+1])+1 print(DP[n][m])