#include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef ONLINE_JUDGE //POJ # include # include # include # define mkt make_tuple # define empb emplace_back #endif #ifdef _LOCAL # include "for_local.h" #endif using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I)) #define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I)) #define mkp make_pair #define all(_X) (_X).begin(), (_X).end() inline int scani() { int n; scanf("%d", &n); return n; } int const INF = 1<<29; int n,m; string s, t; int const N = 1000 + 1; #if 1 int memo[N][N][2]; int dfs(int is, int it, int k) { if ( is == n || it == m ) return (n - is) + (m - it); auto& x = memo[is][it][k]; if ( x != INF + 1 ) { return x; } if ( s[is] == t[it] ) { return x = dfs(is + 1, it + 1, k); } else { return x = min(dfs(is + 1, it + 1, k) + 1, min(dfs(is + 1, it, 1 - k) + 1, dfs(is, it + 1, 1 - k) + 1)); } } int calc() { rep(i, N) rep(j, N) rep(k, 2) memo[i][j][k] = INF + 1; return dfs(0, 0, (m - n) & 1); } #endif signed main() { cin >> n >> m >> s >> t; if ( n > m ) { swap(n, m); swap(s, t); } s.append("*"); t.append("*"); int const c = calc(); cout << c << endl; return 0; }