import java.util.Scanner object Problem225 { def proc(n: Int, m: Int, S: String, T: String): Int = { val dp = Array.fill(n + 1, m + 1)(0) (0 to S.length) foreach (i => dp(i)(0) = i) (0 to T.length) foreach (i => dp(0)(i) = i) for (i <- 1 to S.length; j <- 1 to T.length) { val cost = if (S(i - 1) == T(j - 1)) 0 else 1 dp(i)(j) = Seq(dp(i - 1)(j) + 1, dp(i)(j - 1) + 1, dp(i - 1)(j - 1) + cost).min } dp(S.length)(T.length) } def main(args: Array[String]) { val sc = new Scanner(System.in) val (n, m) = (sc.nextInt(), sc.nextInt()) val S = sc.next() val T = sc.next() val result = proc(n, m, S, T) println(result) } }