#include <bits/stdc++.h>
using namespace std;
int n, t;
char m[500005];
int hcnt, scnt, hl[500005], sl[500005];
bool ok(int k) {
  int tleft = t, kleft = k, px = -1, mx = -1, sp = 0;
  for (int i = 0; i < hcnt; i++) {
    tleft -= hl[i] - px;
    px = hl[i];
    mx = max(mx, hl[i]);
    if (tleft < 0) return false;
    if (kleft)
      kleft--;
    else {
      if (sp == scnt) return false;
      if (tleft - 2 * (max(hl[hcnt - 1], sl[hcnt - k - 1]) - hl[i]) >= 0)
        return true;
      if (sl[sp] > mx) {
        tleft -= 2 * (sl[sp] - mx);
        mx = sl[sp];
      }
      sp++;
      if (tleft < 0) return false;
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &t);
  scanf(" %s", m);
  hcnt = scnt = 0;
  for (int i = 0; i < n; i++) {
    if (m[i] == 'H')
      hl[hcnt++] = i;
    else if (m[i] == 'S')
      sl[scnt++] = i;
  }
  if (t <= hl[hcnt - 1]) {
    printf("-1\n");
    return 0;
  }
  int lo = max(0, hcnt - scnt), hi = hcnt;
  while (lo < hi) {
    int k = (lo + hi) / 2;
    if (ok(k))
      hi = k;
    else
      lo = k + 1;
  }
  printf("%d\n", lo);
  return 0;
}
