#include <bits/stdc++.h>
using namespace std;
const int maxn = 500500;
int n, lim, l, r, maxdist, a[maxn], f[maxn];
bool Work(int now) {
  int qian = 0, last = 0, t = lim;
  for (int i = 1; i <= n; ++i) {
    --t;
    if (t < 0) return false;
    if ((!qian) && (i + t / 2 >= maxdist) &&
        (f[min(i + t / 2, n)] - f[i - 1] + now >= qian))
      return true;
    if (a[i] == 1) {
      ++now;
      if ((qian) && (now == qian)) {
        t -= i - last + min(i, maxdist) - last, qian = now = 0;
        if (t < 0) return false;
      }
    }
    if (a[i] == 2)
      if (now)
        --now;
      else {
        ++qian;
        if (qian == 1) last = i;
      }
    if ((i >= maxdist) && (!qian)) return true;
  }
  return false;
}
int main() {
  scanf("%d%d\n", &n, &lim);
  for (int i = 1; i <= n; ++i) {
    char c = getchar();
    if (c == 'S') a[i] = 1;
    if (c == 'H') a[i] = 2, maxdist = i;
  }
  if (maxdist > lim) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    f[i] = f[i - 1] + (int)(a[i] == 1) - (int)(a[i] == 2);
  l = 0;
  r = maxdist;
  while (l != r) {
    int m = (l + r) >> 1;
    if (Work(m))
      r = m;
    else
      l = m + 1;
  }
  printf("%d\n", l);
  return 0;
}
