import java.util.*; public class Main { static char[] sArr; static char[] tArr; static int[][] dp; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); sArr = sc.next().toCharArray(); tArr = sc.next().toCharArray(); dp = new int[n][m]; for (int[] arr : dp) { Arrays.fill(arr, -1); } System.out.println(dfw(n - 1, m - 1)); } static int dfw(int s, int t) { if (s < 0) { return t + 1; } if (t < 0) { return s + 1; } if (dp[s][t] < 0) { if (sArr[s] == tArr[t]) { dp[s][t] = dfw(s - 1, t - 1); } else { dp[s][t] = Math.min(Math.min(dfw(s - 1, t), dfw(s - 1, t - 1)), dfw(s, t - 1)) + 1; } } return dp[s][t]; } }