#include <limits>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<typename Type> class StarrySkyTree {
private:
	unsigned size_; std::vector<Type> dat1, dat2;
	inline void update_(unsigned a, unsigned b, Type x, unsigned k, unsigned l, unsigned r) {
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			dat2[k] += x; return;
		}
		update_(a, b, x, (k << 1), l, (l + r) >> 1);
		update_(a, b, x, (k << 1) + 1, (l + r) >> 1, r);
		dat1[k] = std::min(dat1[k << 1] + dat2[k << 1], dat1[(k << 1) + 1] + dat2[(k << 1) + 1]);
	}
	inline Type query_(unsigned a, unsigned b, unsigned k, unsigned l, unsigned r) {
		if (r <= a || b <= l) return std::numeric_limits<Type>::max();
		if (a <= l && r <= b) return dat1[k] + dat2[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc) + dat2[k];
	}
public:
	StarrySkyTree() : size_(0), dat1(std::vector<Type>()), dat2(std::vector<Type>()) {};
	StarrySkyTree(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat1.resize(size_ << 1, 0);
		dat2.resize(size_ << 1, 0);
	}
	inline unsigned size() { return size_; }
	inline void add(unsigned i, Type x) {
		update_(i, i + 1, x, 1, 0, size_);
	}
	inline void add(unsigned l, unsigned r, Type x) {
		update_(l, r, x, 1, 0, size_);
	}
	inline Type query(unsigned l, unsigned r) {
		return query_(l, r, 1, 0, size_);
	}
};
const int inf = 1012345678;
int n, m, dp[500009]; string s, t;
int solve() {
	t += 'X';
	StarrySkyTree<int> v1(n + 1), v2(n + 1);
	for (int i = 0; i < n; i++) {
		if (t[i] == 'B' && (i == 0 || t[i - 1] == 'W')) {
			v1.add(0, i + 1, 1);
		}
		if (t[i] == 'W' && (i == 0 || t[i - 1] == 'B')) {
			v2.add(0, i + 1, 1);
		}
		dp[i + 1] = inf;
		if (s[i] == t[i]) dp[i + 1] = dp[i];
		int res1 = v1.query(max(0, i - m + 1), i + 1) + 1;
		int res2 = v2.query(max(0, i - m + 1), i + 1) + 1;
		dp[i + 1] = min({ dp[i + 1], res1, res2 });
		v1.add(i + 1, (t[i + 1] == 'W' ? dp[i + 1] : inf));
		v2.add(i + 1, (t[i + 1] == 'B' ? dp[i + 1] : inf));
	}
	t.pop_back();
	return dp[n];
}
#include <map>
#include <queue>
#include <cassert>
int brute_force() {
	queue<string> que; que.push(s);
	map<string, int> dist; dist[s] = 0;
	map<string, bool> vis; vis[s] = true;
	if (s == t) return 0;
	while (!que.empty()) {
		string u = que.front(); que.pop();
		for (int i = 0; i < n; i++) {
			for (int j = 1; j <= m && i + j <= n; j++) {
				for (int k = 0; k < 2; k++) {
					string u2 = u;
					for (int l = i; l < i + j; l++) u2[l] = (k ? 'W' : 'B');
					if (!vis[u2]) {
						vis[u2] = true;
						dist[u2] = dist[u] + 1;
						que.push(u2);
						if (u2 == t) return dist[u2];
					}
				}
			}
		}
	}
	return -1;
}
int rand_rng(int l, int r) {
	long long seed = rand() * 123456789LL + rand() * 3456789LL + rand() * 12345LL;
	return l + (seed) % (r - l);
}
void random_test() {
	n = 8; m = 4;
	for (int i = 0; i < 10000; i++) {
		s.clear();
		t.clear();
		for (int j = 0; j < n; j++) s += (rand_rng(0, 2) ? 'W' : 'B');
		for (int j = 0; j < n; j++) t += (rand_rng(0, 2) ? 'W' : 'B');
		int res1 = solve();
		int res2 = brute_force();
		cout << "Case #" << i << ": " << "n = " << n << ", m = " << m << ", s = " << s << ", t = " << t << endl;
		assert(res1 == res2);
	}
}
int main() {
	//random_test();
	ios::sync_with_stdio(false);
	cin >> n >> m >> s >> t;
	int ret = solve();
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 22904