#include <bits/stdc++.h>
using namespace std;
int g_s[600010], glen, last, iHouse;
char gsz[600010];
int gLast[600010];
int search(int val, int pos, int &house) {
  int i;
  house = 0;
  for (i = pos + 1; i <= glen; i++) {
    if (gsz[i] == 'H') house++;
    if (g_s[i] >= val) break;
  }
  return i;
}
int check(int val, int time, int icnt) {
  int i, pos, left = time;
  int now = val, house;
  for (i = 1; i <= glen;) {
    if (!icnt) return 1;
    if (left > 0)
      left--;
    else
      return 0;
    if (gsz[i] == 'H') {
      icnt--;
      if (now > 0) {
        now--;
        i++;
      } else {
        int ttmp;
        if ((gLast[val] - i) * 2 <= left) return 1;
        pos = search(-val, i, house);
        ttmp = (pos - i) * 3;
        if (ttmp <= left) {
          left -= ttmp;
          i = pos + 1;
          icnt -= house;
          continue;
        }
        return 0;
      }
    } else if (gsz[i] == 'S') {
      i++;
      now++;
    } else
      i++;
  }
  return 1;
}
int main() {
  int i, j, n, time, cntshop = 0, ilast;
  scanf("%d%d", &n, &time);
  glen = n;
  scanf("%s", gsz + 1);
  for (i = 1; gsz[i]; i++) {
    if (gsz[i] == 'S') {
      g_s[i] = g_s[i - 1] + 1;
      cntshop++;
    } else if (gsz[i] == 'H') {
      iHouse++;
      g_s[i] = g_s[i - 1] - 1;
      ilast = i;
    } else
      g_s[i] = g_s[i - 1];
  }
  if (time < ilast) {
    puts("-1");
    return 0;
  }
  for (i = ilast + 1; i <= glen; i++) {
    if (gsz[i] == 'S') {
      if (g_s[i] > 0) break;
      gLast[-g_s[i]] = i;
    }
  }
  int low, high = iHouse, mid;
  if (cntshop >= iHouse)
    low = 0;
  else
    low = iHouse - cntshop;
  for (i = low; i <= iHouse; i++) gLast[i] = max(gLast[i], ilast);
  while (low <= high) {
    mid = (low + high) >> 1;
    if (check(mid, time, iHouse)) {
      high = mid - 1;
    } else
      low = mid + 1;
  }
  printf("%d\n", low);
  return 0;
}
