using System; class MainClass { public static void Main(string[] args) { string[] s1 = Console.ReadLine().Split(' '); int n = int.Parse(s1[0]); int m = int.Parse(s1[1]); string S = Console.ReadLine(); string T = Console.ReadLine(); int[,] dp = new int[n + 1, m + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) dp[i, j] = 1000; dp[0, 0] = 0; for (int i = 0; i < n;i++) { for (int j = 0; j < m;j++) { if(S[i]==T[j]) { dp[i + 1, j + 1] = Math.Min(dp[i, j], dp[i + 1, j] + 1); dp[i + 1, j + 1] = Math.Min(dp[i + 1, j + 1], dp[i, j + 1] + 1); } else { dp[i + 1, j + 1] = Math.Min(dp[i, j] + 1, dp[i + 1, j] + 1); dp[i + 1, j + 1] = Math.Min(dp[i + 1, j + 1], dp[i, j + 1] + 1); } } } Console.WriteLine(dp[n,m]); } }