#include <bits/stdc++.h>
using namespace std;
void read(int &k) {
  k = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    k = k * 10 - 48 + x;
    x = getchar();
  }
}
int n, T;
char s[500010];
bool calc(int now) {
  int tim = 0, nd = 0, las = 0;
  int tmp = -now, ed = 0, maxt = 0;
  for (int i = 1; i <= n; i++)
    if (s[i] == 'H') tmp++, maxt = i;
  if (maxt > T) return 0;
  for (ed = 1; ed <= n && tmp > 0; ed++)
    if (s[ed] == 'S' && tmp >= 0) tmp--;
  if (tmp > 0) return 0;
  ed--;
  if (!ed) return 1;
  for (int i = 1; i <= n && tim <= T; i++) {
    tim++;
    if (s[i] == 'H') {
      if (now) {
        now--;
        if (i >= maxt) return tim <= T;
      } else {
        if (!nd) {
          las = i, nd = 1;
          if (tim + (max(ed, maxt) - i) * 2 <= T) return 1;
        } else
          nd++;
      }
    } else if (s[i] == 'S') {
      if (nd) {
        if (nd > 1)
          nd--;
        else {
          tim += (i - las) * 2;
          nd--;
        }
      } else
        now++;
    }
  }
  return tim <= T;
}
int main() {
  scanf("%d%d", &n, &T);
  scanf("%s", s + 1);
  int L, R, ans;
  for (L = 0, R = n, ans = -1; L <= R;) {
    int t = (L + R) / 2;
    if (calc(t))
      R = t - 1, ans = t;
    else
      L = t + 1;
  }
  printf("%d\n", ans);
  return 0;
}
