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 == 0: return m if m == 0: return n 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)