N,M=map(int,input().split()) S=input() T=input() dp=[[10**18]*(M+1) for _ in range(N+1)] dp[0][0]=0 for i in range(N+1): for j in range(M+1): if i>0: dp[i][j] = min(dp[i][j], dp[i-1][j]+1 ) if j>0: dp[i][j] = min(dp[i][j], dp[i][j- 1]+1) if j>0 and i>0: dp[i][j] = min(dp[i][j], dp[i-1][j-1]+(S[i-1]!=T[j-1])) print(dp[N][M])