def Levenshtein_dist(S,T): s=len(S) t=len(T) dp=[[1145141919810931 for i in range(t+1)] for j in range(s+1)] dp[0][0]=0 for i in range(-1,s): for j in range(-1,t): if i==-1 and j==-1: continue elif i>=0 and j>=0: if S[i]==T[j]: dp[i+1][j+1]=min(dp[i][j],dp[i][j+1]+1, dp[i+1][j]+1) else: dp[i+1][j+1]=min(dp[i][j]+1,dp[i][j+1]+1, dp[i+1][j]+1) elif i>=0: dp[i+1][j+1]=dp[i][j+1]+1 elif j>=0: dp[i+1][j+1]=dp[i+1][j]+1 return dp[s][t] _,_=map(int,input().split()) S=input() T=input() print(Levenshtein_dist(S,T))