#include<bits/stdc++.h>
#define int long long
using namespace std;
// auto IN = freopen("cowreography.in", "r", stdin);
// auto OUT = freopen("cowreography.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1e6 + 5;
int n = mread(), m = mread(), ans = 0;
char s[N], t[N];
signed main(){
scanf("%s", s + 1);
scanf("%s", t + 1);
for(int i = 1; i <= n; i ++){
if(s[i] == '1' && t[i] == '0'){
int p = 0;
for(int j = 1; j < i; j ++){
if(s[j] == '0' && t[j] == '1'){
if(p == 0 || (j - i + n * m) % m < (p - i + n * m) % m){
p = j;
}
}
}
if(p != 0){
ans += ((i - p) + m - 1) / m;
swap(s[i], s[p]);
}
}
else if(s[i] == '0' && t[i] == '1'){
int p = 0;
for(int j = 1; j < i; j ++){
if(s[j] == '1' && t[j] == '0'){
if(p == 0 || (j - i + n * m) % m < (p - i + n * m) % m){
p = j;
}
}
}
if(p != 0){
ans += ((i - p) + m - 1) / m;
swap(s[i], s[p]);
}
}
}
printf("%lld", ans);
return 0;
}