import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); String S = sc.next(); String T = sc.next(); S+="-"; T+="-"; int dp[][]=new int[1010][1010]; for(int i=0;i<1010;i++) Arrays.fill(dp[i], 114514); dp[0][0]=0; for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ if( S.charAt(i)==T.charAt(j)){ dp[i+1][j+1]=Math.min(dp[i+1][j+1], dp[i][j]); }else{ dp[i+1][j+1]=Math.min(dp[i+1][j+1], dp[i][j]+1); } dp[i+1][j]=Math.min(dp[i+1][j], dp[i][j]+1); dp[i][j+1]=Math.min(dp[i][j+1], dp[i][j]+1); } } System.out.println(dp[n][m]); } }