#include <bits/stdc++.h>
using namespace std;
int Read() {
  char c;
  while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
    ;
  bool neg = (c == '-');
  int ret = (neg ? 0 : c - 48);
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
  return neg ? -ret : ret;
}
const int MAXN = 500005;
char s[MAXN];
int N, T, last = 0, l, r, ans, a[MAXN], b[MAXN];
void init() {
  scanf("%d%d%s", &N, &T, s + 1);
  for (int i = 1; i <= N; i++) {
    a[i] = s[i] == 'S' ? 1 : s[i] == 'H' ? -1 : 0;
    if (a[i] < 0) last = i, r++, l++;
    if (a[i] > 0) l--;
  }
}
bool check(int aim) {
  int maxpos = last;
  b[0] = aim;
  for (int i = 1; i <= N; i++) {
    b[i] = b[i - 1] + a[i];
    if (!b[i] && b[i - 1] < 0) maxpos = max(maxpos, i);
  }
  int cnt = 0, ls = 0, tmp = T;
  for (int i = 1; i <= maxpos; i++) {
    if (b[i - 1] < 0 && !b[i]) {
      if (i == maxpos) tmp = min(tmp, cnt + maxpos - ls);
      cnt += (i - ls) * 2;
    }
    if (b[i] < 0 && !b[i - 1]) tmp = min(tmp, cnt + (maxpos - i) * 2), ls = i;
    cnt++;
  }
  return min(tmp, cnt - 1) < T;
}
void work() {
  if (last > T) {
    puts("-1");
    return;
  }
  if (!last) {
    puts("0");
    return;
  }
  l = max(l, 0);
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
}
int main() {
  init();
  work();
  return 0;
}
