#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyBvcnogbGFvZnVkYXN1YW4KLy8gbW9kaWZpZWQKCm5hbWVzcGFjZSBpbyB7Cgljb25zdCBpbnQg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