#include <bits/stdc++.h>
const int N = 500005;
int n, t, Hpos;
char temp[N];
int Fin(int ans) {
  int Up_pos = -1, Up_dis = -1;
  int neg = N + 1, cost = 0;
  for (int i = 0; i < n; i++) {
    if (ans >= 0 && i > Hpos) break;
    cost++;
    if (temp[i] == 'H') {
      ans--;
      if (ans == -1) neg = i;
      if (i == Hpos && ans >= 0) {
        if (Up_dis > i - Up_pos) cost -= (Up_dis - i + Up_pos);
      }
    }
    if (temp[i] == 'S') {
      ans++;
      if (ans == 0) {
        if (i > Hpos) {
          cost += (i - neg);
          if (Up_dis > i - Up_pos) cost -= (Up_dis - i + Up_pos);
        } else {
          cost += 2 * (i - neg);
          Up_pos = i;
          Up_dis = i - neg;
        }
      }
    }
  }
  if (cost > t || ans < 0)
    return 1;
  else
    return 0;
}
int main() {
  int l, r;
  while (~scanf("%d%d", &n, &t)) {
    scanf("%s", &temp);
    Hpos = n - 1;
    l = r = 0;
    while (temp[Hpos] != 'H') Hpos--;
    for (int i = 0; i <= Hpos; i++)
      if (temp[i] == 'H') r++;
    if (Hpos + 1 > t)
      printf("-1\n");
    else {
      int ans;
      while (l <= r) {
        int m = (l + r) >> 1;
        int s = Fin(m);
        if (s)
          l = m + 1;
        else
          r = m - 1;
      }
      printf("%d\n", l);
    }
  }
  return 0;
}
