import sys sys.setrecursionlimit(10000) N, M = map(int, raw_input().split()) s1, s2 = raw_input(), raw_input() mem = {} def rec(n, m): if (n, m) in mem: return mem[(n, m)] if n == m == -1: return 0 if n == -1: return m+1 if m == -1: return n+1 mem[(n, m)] = min(rec(n-1, m)+1, rec(n, m-1)+1, rec(n-1, m-1)+(s1[n]!=s2[m])) return mem[(n, m)] print rec(N-1, M-1)