#include <bits/stdc++.h>
using namespace std;
int n, t, sum;
const int N = 5e5 + 20;
char st[N];
bool check(int x) {
  int cnt = 0, pos1 = 0, pos2 = 0, sub = 0, s = t;
  for (int i = 1; i <= n; i++) {
    if (cnt == sum && x >= 0) return s >= min(i - pos1, sub);
    s--;
    if (st[i] == 'H') {
      if (!x) {
        if (!pos1) pos1 = i;
        pos2 = i;
      }
      x--;
      cnt++;
    } else if (st[i] == 'S') {
      x++;
      if (!x) {
        sub += i - pos2;
        if (cnt != sum) sub += i - pos2;
      }
    }
  }
  return s >= min(n - pos1, sub) && x >= 0;
}
int main() {
  scanf("%d%d", &n, &t);
  scanf("%s", st + 1);
  for (int i = 1; i <= n; i++) sum += (st[i] == 'H');
  int l = 0, r = sum;
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (check(l))
    printf("%d\n", l);
  else
    printf("-1\n");
  return 0;
}
