#include <bits/stdc++.h>
using namespace std;
char s[500010];
int len, lasth;
bool ok(int x, int num) {
  int now = x, pre = -1, tt = 0, end = -1;
  for (int i = 0; i < len; i++) {
    if (s[i] == 'H')
      now--;
    else if (s[i] == 'S')
      now++;
    if (now >= 0 && i >= lasth) {
      end = i;
      break;
    }
  }
  now = x;
  if (end == -1) return false;
  int cost = 0, ans = num + 100;
  for (int i = 0; i <= end; i++) {
    cost++;
    if (s[i] == 'H') {
      now--;
      if (now == -1) pre = i;
    } else if (s[i] == 'S') {
      now++;
      if (now == 0) {
        ans = min(ans, cost + (end - i) + (end - pre));
        cost += (i - pre) * 2;
      }
    }
  }
  ans = min(ans, cost);
  return ans <= num;
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    scanf("%s", s);
    len = strlen(s);
    int hs = 0, ss = 0;
    int ll = 0, rr = len;
    for (int i = 0; i < len; i++)
      if (s[i] == 'H') lasth = i;
    while (ll + 1 < rr) {
      int mid = (ll + rr) / 2;
      if (ok(mid, m))
        rr = mid;
      else
        ll = mid;
    }
    if (ok(ll, m))
      printf("%d\n", ll);
    else if (ok(rr, m))
      printf("%d\n", rr);
    else
      puts("-1");
  }
  return 0;
}
