import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class Main { //https://qiita.com/drken/items/a5e6fe22863b7992efdb //#10 public static void main(String[] args) { FastScanner scan = new FastScanner(); long mod = 998244353L; int n = scan.nextInt(); int m = scan.nextInt(); // long k = scan.nextLong(); // long[] a = new long[n]; // long[] v = new long[n]; // long[] z = new long[n]; // int bit = 0; String s = scan.next(); String t = scan.next(); long [][] dp = new long[s.length()+1][t.length()+1]; //dp[s.length][t.length] : Sのs.length文字までとTの・・・での最長ぶぶん文字列 // long count = 0L; // double min = 200; // for (int i = 0; i < n; i++) { // a[i] = scan.nextLong(); // v[i] = scan.nextLong(); // z[i] = scan.nextLong(); // } dp[0][0]= 0L; for (int i = 1; i <= s.length(); i++) { dp[i][0] = i; } for (int i = 1; i <= t.length(); i++) { dp[0][i] = i; } for (int i = 0; i < s.length(); i++) { for (int j = 0; j < t.length(); j++) { if(s.charAt(i)==t.charAt(j)) { dp[i+1][j+1] = dp[i][j]; } else { dp[i+1][j+1] = Math.min(dp[i][j]+1, dp[i+1][j]+1); dp[i+1][j+1] = Math.min(dp[i+1][j+1], dp[i][j+1]+1); } } } System.out.println(dp[s.length()][t.length()]); } static long dp(int bit, int now, long[][] dp , int n, long[]x, long[]y, long[]z) { if(dp[bit][now] >0) { return dp[bit][now]; } if (bit == (1<=0 && a[p-1]>a[p]) --p; if (p==0) return false; int q=p; while (q+1 Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} } }