class Solver:
    def __init__(self) -> None:
        self.s1 = ""
        self.s2 = ""
        self.n = 0
        self.m = 0

    def read_input(self) -> None:
        (self.n,self.m) = map(int, input().split())
        (self.s1,self.s2) = input().split()

    def solve(self) -> None:
        dp: list[list[int]] = [[0] * (self.m + 1) for _ in range(self.n + 1)]
        for i in range(self.n + 1):
            dp[i][0] = i
        for j in range(self.m + 1):
            dp[0][j] = j
        for i in range(1, self.n + 1):
            for j in range(1, self.m + 1):
                if self.s1[i - 1] == self.s2[j - 1]:
                    dp[i][j] = dp[i - 1][j - 1]
                else:
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i]
                                   [j - 1] + 1, dp[i - 1][j - 1] + 1)
        print(dp[self.n][self.m])


def main():
    solver = Solver()
    solver.read_input()
    solver.solve()


if __name__ == "__main__":
    main()
