#include <bits/stdc++.h>
using namespace std;
int n, t;
char s[512345];
int cnt_h, cnt_s, last_h;
int c[2][512345];
void setup() {
  for (int i = 0; i < n; i++)
    if (s[i] == 'H') {
      last_h = i;
      cnt_h++;
    } else if (s[i] == 'S')
      cnt_s++;
}
int calc(int st) {
  if (st + cnt_s < cnt_h) return t + 1;
  int p = 0, it = 0, sum = st;
  bool f = 1;
  c[0][0] = c[1][0] = 0;
  for (; p <= last_h || sum < 0; p++) {
    c[f][it]++;
    if (s[p] == 'H')
      sum--;
    else if (s[p] == 'S')
      sum++;
    if (sum < 0 && f == 1) {
      it++;
      c[0][it] = c[1][it] = 0;
      f = 0;
    } else if (sum >= 0 && f == 0)
      f = 1;
  }
  int res = 0, tmp = 0;
  for (int i = 0; i <= it; i++) res += c[0][i] * 3 + c[1][i];
  tmp = res;
  for (int i = it; i >= 0; i--) {
    tmp += c[1][i] - c[0][i];
    res = min(res, tmp);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &t);
  scanf("%s", &s);
  setup();
  int l = 0, r = n, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (calc(mid) <= t) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
