import java.io.*; import java.util.*; public class Main { static char[] start; static char[] term; static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); start = sc.next().toCharArray(); term = 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 x, int y) { if (x < 0) { return y + 1; } if (y < 0) { return x + 1; } if (dp[x][y] < 0) { if (start[x] == term[y]) { dp[x][y] = dfw(x - 1, y - 1); } else { dp[x][y] = Math.min(dfw(x - 1, y - 1), Math.min(dfw(x - 1, y), dfw(x, y - 1))) + 1; } } return dp[x][y]; } } 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 { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }