#include<iostream>
using namespace std;
int main(){
int len1, len2;
string text1,text2;
cin >> len1 >> len2;
cin >> text1 >> text2;
int distance[len1 +1][len2 + 1];
distance[0][0] = 0;
for(int i = 1; i < len1 +1 ; i++)
distance[i][0] = i;
for(int i = 1; i < len2 +1 ; i++)
distance[0][i] = i;
for(int i = 1; i < len1 +1 ; i++){
for(int j = 1; j < len2 +1 ; j++){
if(text1[i -1] == text2[j -1]){
distance[i][j] = distance[i-1][j-1];
} else {
int min = max(len1, len2);
if (distance[i-1][j]+1 < min)
min = distance[i-1][j]+1;
if (distance[i][j-1]+1 < min)
min = distance[i][j-1]+1;
if (distance[i-1][j-1]+1 < min)
min = distance[i-1][j-1]+1;
distance[i][j] = min;
}
}
}
cout<<distance[len1][len2];;
return 0;
}