#include <bits/stdc++.h>
char s[500100];
int n, t;
int Last;
int a[500100];
const int inf = (1 << 30);
int calcT(int cnt) {
  bool bf = 0;
  if (cnt == 0) bf = 1;
  int LastV = n, ret = 0, tp;
  for (int i = 0; i < n; i++) {
    if (cnt >= 0 && i > Last) {
      LastV = i;
      break;
    }
    a[i] = 1;
    if (cnt < 0) a[i]++;
    if (s[i] == 'H')
      cnt--;
    else if (s[i] == 'S')
      cnt++;
    if (cnt < 0) a[i]++;
    ret += a[i];
  }
  if (cnt < 0) return inf;
  tp = ret;
  for (int i = LastV - 1; i >= 0; i--) {
    if (i == LastV - 1)
      tp += 1 - a[i];
    else
      tp += 2 - a[i];
    if (ret > tp) ret = tp;
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &t);
  scanf("%s", s);
  for (int i = 0; i < n; i++)
    if (s[i] == 'H') Last = i;
  int lo = 0, hi = n + 1;
  while (hi - lo > 1) {
    int m = (lo + hi) >> 1;
    if (calcT(m) <= t)
      hi = m;
    else
      lo = m;
  }
  if (calcT(lo) <= t)
    printf("%d\n", lo);
  else if (calcT(hi) <= t)
    printf("%d\n", hi);
  else
    puts("-1");
}
