def min(a,b,c): if a>b: if b>c: return c else: return b else: if a>c: return c else: return a n,m = map(int,input().split()) S=input() T=input() inf=float('inf') a=[] for i in range(0,n+1): a.append([inf]*(m+1)) a[0][0]=0 for i in range(0,n+1): for j in range(0,m+1): if j==0 and i==0: continue elif j==0: a[i][j]=a[i-1][j]+1 elif i==0: a[i][j]=a[i][j-1]+1 else: if S[i-1]==T[j-1]: a[i][j]=a[i-1][j-1] else: a[i][j]=min(a[i][j-1],a[i-1][j],a[i-1][j-1])+1 print(a[n][m])