N,M = map(int,input().split()) S = input() T = input() DP = [[10**5]*(M+1) for _ in range(N+1)] DP[0][0]=0 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]) else: DP[i+1][j+1]=min(DP[i+1][j+1],DP[i][j]+1) DP[i+1][j]=min(DP[i+1][j],DP[i][j]+1) DP[i][j+1]=min(DP[i][j+1],DP[i][j]+1) print(min(DP[N][M],DP[N-1][M]+1,DP[N][M-1]+1))