#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long inf = 0xc0c0c0c0c0c0c0c0;
const double pi = acos(-1);
const int MAXL = 5e5 + 7;
int limit, len;
char str[MAXL];
int tag[MAXL];
int tot;
int judge(int have) {
  int last;
  int cpy = have;
  int f = 0;
  for (last = 0; last < len; last++) {
    if (str[last] == 'H')
      f++;
    else if (str[last] == 'S')
      cpy++;
    if (cpy >= f && f == tot) break;
  }
  if (last == len) return 0;
  memset(tag, 0, sizeof(tag));
  int sz = 0;
  int pos = -1;
  int t = 0;
  for (int i = 0; i <= last; i++) {
    t++;
    if (str[i] == 'H') {
      if (have)
        have--;
      else {
        sz++;
        if (pos == -1) pos = i;
      }
    } else if (str[i] == 'S') {
      have++;
      if (sz && have >= sz) {
        tag[pos] = (i - pos) << 1;
        t += tag[pos];
        have -= sz;
        sz = 0;
        pos = -1;
      }
    }
  }
  int res = t;
  for (int i = last; ~i; i--) {
    if (str[i] == 'H') t -= tag[i];
    res = min(res, t);
    t++;
  }
  return res <= limit;
}
int main() {
  scanf("%d%d%s", &len, &limit, str);
  for (int i = 0; i < len; i++) tot += str[i] == 'H';
  if (!judge(len)) {
    puts("-1");
    return 0;
  }
  int low = -1;
  int high = len + 2;
  while (low + 1 < high) {
    int mid = (low + high) >> 1;
    if (judge(mid))
      high = mid;
    else
      low = mid;
  }
  printf("%d\n", high);
  return 0;
}
