#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, n, t;
char base[500005];
int bp[500005], bk[500005], sums[500005];
int main() {
  scanf("%d%d", &n, &t);
  scanf("%s", base + 1);
  for (a = t + 1; a <= n; a++)
    if (base[a] == 'H') {
      printf("-1");
      return 0;
    }
  int top, bot;
  top = n;
  bot = 0;
  for (a = 1; a <= n; a++) {
    if (base[a] == 'H') bot++;
    if (base[a] == 'S') bot--;
  }
  if (bot < 0) bot = 0;
  while (top > bot) {
    int tr = (top + bot) / 2;
    int now = tr;
    int backnum = 0;
    for (a = 1; a <= n; a++) {
      if (base[a] == 'H') {
        if (now == 0) {
          backnum++;
          bp[backnum] = a;
        }
        now--;
      }
      if (base[a] == 'S') {
        now++;
        if (now == 0) {
          bk[backnum] = a;
        }
      }
    }
    if (backnum == 0)
      top = tr;
    else {
      for (a = 1; a <= backnum; a++)
        sums[a] = sums[a - 1] + (bk[a] - bp[a]) * 2;
      int sol = sums[backnum];
      int posl = bk[backnum];
      for (a = posl; a <= n; a++)
        if (base[a] == 'H') posl = a;
      a = backnum;
      while (a >= 1 && sums[a - 1] + posl - bp[a] < sol)
        sol = sums[a - 1] + posl - bp[a], a--;
      if (sol + posl <= t)
        top = tr;
      else
        bot = tr + 1;
    }
  }
  printf("%d\n", top);
}
