import java.util.*; import java.math.*; public class Main { static int[][] dp; static char[] aArr; static char[] bArr; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); dp = new int[n][m]; aArr = sc.next().toCharArray(); bArr = sc.next().toCharArray(); System.out.println(getCount(0, 0)); } static int getCount(int aIdx, int bIdx) { if (aIdx == aArr.length) { return bArr.length - bIdx; } if (bIdx == bArr.length) { return aArr.length - aIdx; } if (dp[aIdx][bIdx] != 0) { return dp[aIdx][bIdx]; } int min; if (aArr[aIdx] == bArr[bIdx]) { min = getCount(aIdx + 1, bIdx + 1); } else { min = getCount(aIdx + 1, bIdx + 1) + 1; min = Math.min(min, getCount(aIdx + 1, bIdx) + 1); min = Math.min(min, getCount(aIdx, bIdx + 1) + 1); } dp[aIdx][bIdx] = min; return min; } }