#include #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i < (n + 1); ++i) const double PI = 3.141592653589793238463; using namespace std; using ll = long long; const ll INF = 1LL << 50; typedef pair P; const int mod = 1e9 + 7; const int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0}; const int ddx[] = {0,1,0,-1,1,1,-1,-1}, ddy[] = {1,0,-1,0,1,-1,1,-1}; int main() { string S,T; int n,m; cin >> n >> m; cin >> S >> T; int dp[1010][1010]; memset(dp, 0, sizeof(dp)); rep(i,S.size()) { rep(j, T.size()) { if(S[i]==T[j]) dp[i+1][j+1] = dp[i][j]; else dp[i+1][j+1] = min(min(dp[i+1][j] + 1,dp[i][j+1] + 1), dp[i][j]+1); } } cout << dp[S.size()][T.size()] << endl; return 0; }