#include "bits/stdc++.h" using namespace std; typedef long long ll; const int INF = 1<<29; int n, m; string s, t; int dp[1100][1100]; int main() { cin >> n >> m; cin >> s >> t; for(int i=0; i<1100; i++) for(int j=0; j<1100; j++) dp[i][j] = INF; dp[0][0] = 0; for (int i = -1; i < (int)s.size(); i++) { for (int j = -1; j < (int)t.size(); j++) { if(i==-1 && j==-1) continue; if (i >= 0 && j >= 0) { if(s[i] == t[j]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+1); } if(i>=0) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]+1); if(j>=0) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]+1); } } cout << dp[s.size()][t.size()] << endl; }