def read_data(): n, m = map(int, input().split()) S = input().strip() T = input().strip() return n, m, S, T memo = dict() def f(a, b, S, T): ''' f(a, b, S, T) S[:a] を T[:b] に変更するのに必要な最低ステップ数 ''' global memo if (a, b) in memo: return memo[a, b] if a == 0: return b if b == 0: return a s = S[a - 1] t = T[b - 1] if s == t: memo[a, b] = f(a-1, b-1, S, T) return memo[a, b] if s != t: steps_change = 1 + f(a-1, b-1, S, T) steps_insert = 1 + f(a, b-1, S, T) steps_delete = 1 + f(a-1, b, S, T) memo[a, b] = min(steps_change, steps_insert, steps_delete) return memo[a, b] if __name__ == '__main__': n, m, S, T = read_data() print(f(n, m, S, T))