import java.util.Scanner; public class Main_yukicoder225 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); char[] s = sc.next().toCharArray(); char[] t = sc.next().toCharArray(); int[][] dp = new int[m + 1][n + 1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0 && j == 0) { continue; } if (i == 0) { dp[i][j] = dp[i][j - 1] + 1; } else if (j == 0) { dp[i][j] = dp[i - 1][j] + 1; } else { if (s[j - 1] == t[i - 1]) { dp[i][j] = dp[i - 1][j - 1]; } else { dp[i][j] = dp[i - 1][j - 1] + 1; } dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + 1); dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + 1); } } } System.out.println(dp[m][n]); sc.close(); } }