import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class No0225 { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static void solve() { int n = in.nextInt(); int m = in.nextInt(); String s = in.next(); String t = in.next(); out.println(levenshteinDistance(s,t)); } static int levenshteinDistance(String s, String t) { int n = s.length(); int m = t.length(); int[][] dp = new int[n+1][m+1]; for (int i=0; i<=n; i++) { for (int j=0; j<=m; j++) { if (i == 0 && j == 0) continue; dp[i][j] = Integer.MAX_VALUE/2; if (i > 0) dp[i][j] = Math.min(dp[i][j], dp[i-1][j] + 1); if (j > 0) dp[i][j] = Math.min(dp[i][j], dp[i][j-1] + 1); if (i > 0 && j > 0) dp[i][j] = Math.min(dp[i][j], dp[i-1][j-1] + (s.charAt(i-1) == t.charAt(j-1) ? 0 : 1)); } } return dp[n][m]; } public static void main(String[] args) { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); out.close(); } static void trace(Object... o) { System.out.println(Arrays.deepToString(o));} }