#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int n, m; scanf("%d %d", &n, &m); char s[n+1], t[m+1]; scanf("%s", s); scanf("%s", t); int d[n+1][m+1]; memset(d, 0, sizeof(d)); for (int i = 0; i < n; i++) { d[i][0] = i; } for (int i = 0; i < m; i++) { d[0][i] = i; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int c = s[i-1] != t[j-1]; d[i][j] = min(d[i-1][j]+1, min(d[i][j-1]+1, d[i-1][j-1]+c)); } } printf("%d\n", d[n][m]); }