import java.io.*; import java.util.*; public class Main { static char[] s; static char[] t; static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); s = sc.next().toCharArray(); t = 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 a, int b) { if (a < 0) { return b + 1; } if (b < 0) { return a + 1; } if (dp[a][b] < 0) { if (s[a] == t[b]) { dp[a][b] = dfw(a - 1, b - 1); } else { dp[a][b] = Math.min(dfw(a - 1, b), Math.min(dfw(a, b - 1), dfw(a - 1, b - 1))) + 1; } } return dp[a][b]; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }