#include <bits/stdc++.h>
using namespace std;

// orz laofudasuan
// modified

namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	inline char getc() { return gc(); }
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;
using io::getc;

const int MAXN = 3.1e5;
int N, K;
char P[MAXN];
pair<pair<int, int>, int> dq[MAXN];

int main() {
	gi(N), gi(K);

	int lo, hi;
	dq[lo=hi=0] = {{0, 0}, 0};
	int pref = 0;
	for (int i = 1, j = i-K; i <= N; i++, j++) {
		if (getc() == 'H') pref ++;
		else pref --;

		auto val = dq[lo].first;
		if (val.second >= pref) val.first++;
		val.second = pref;
		while (lo <= hi && val <= dq[hi].first) --hi;
		dq[++hi] = {val, i};

		if (dq[lo].second == j) lo++;

		if (i == N) {
			cout << val.first << '\n';
		}
	}

	return 0;
}
