#include <bits/stdc++.h>
namespace OI {
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-') f = -1;
  do {
    x = (x << 3) + (x << 1) + (c ^ 48);
  } while (isdigit(c = getchar()));
  x *= f;
}
template <class T>
void pt(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pt(x / 10);
  putchar(x % 10 ^ 48);
}
}  // namespace OI
using namespace OI;
using namespace std;
const int N = 5e5 + 5;
int n, t, sum;
char str[N];
bool check(int x) {
  int cnt = 0, pos1 = -1, 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 (str[i] == 'H') {
      if (x == 0) {
        if (pos1 == -1) pos1 = i;
        pos2 = i;
      }
      x--;
      cnt++;
    } else if (str[i] == 'S') {
      x++;
      if (x == 0) {
        sub += i - pos2;
        if (cnt != sum) sub += i - pos2;
      }
    }
  }
  return s >= min(n - pos1, sub) && x >= 0;
}
int main() {
  rd(n), rd(t);
  scanf("%s", str + 1);
  for (int i = 1; i <= n; i++) sum += str[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))
    pt(l);
  else
    pt(-1);
  return 0;
}
