#include #include using namespace std; int N, M; string S, T; int dp[1001][1001]; int rec(int i, int j){ if(i < 0 || j < 0) return 0; if(i==0 && j == 0) return 0; if(i == 0) return T.size(); if(j == 0) return S.size(); if(dp[i][j] != -1) return dp[i][j]; int ret = 1000001; if(S[i] == T[j]) ret = rec(i-1, j-1); else { ret = min(ret, rec(i-1, j) + 1); ret = min(ret, rec(i, j-1) + 1); ret = min(ret, rec(i-1, j-1) + 1); } return dp[i][j] = ret; } int main(void){ // Your code here! for(int i = 0; i <= 1000; i++) for(int j = 0; j <= 1000; j++) dp[i][j] = -1; cin >> N >> M; cin >> S >> T; cout << rec(S.size()-1, T.size()-1) << endl; }