#include <bits/stdc++.h>
using namespace std;
char s[500010];
vector<int> vs, vh;
bool vis[500010];
int n, t, hh;
bool gao(int mid) {
  int p;
  if (vs.size() + mid < vh.size()) return false;
  int endd =
      max(mid >= vh.size() ? 0 : vs[vh.size() - 1 - mid], vh[vh.size() - 1]);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      if (mid > 0)
        mid--;
      else {
        mid--;
        if (mid == -1) {
          p = i;
          if (t >= (1 + 2 * (endd - i))) return true;
        }
      }
    } else if (s[i] == 'S') {
      mid++;
      if (mid == 0) t -= 2 * (i - p);
    }
    t--;
    if (mid >= 0 && i == vh[vh.size() - 1] && t >= 0) return true;
  }
  return false;
}
int main() {
  int tt;
  while (~scanf("%d%d", &n, &tt)) {
    vs.clear();
    vh.clear();
    scanf("%s", s);
    for (int i = 0; i < n; i++) {
      if (s[i] == 'S')
        vs.push_back(i);
      else if (s[i] == 'H')
        vh.push_back(i);
    }
    int l = 0, r = n;
    while (l < r) {
      int mid = (l + r) / 2;
      t = tt;
      if (gao(mid))
        r = mid;
      else
        l = mid + 1;
    }
    t = tt;
    if (l == n && gao(n) == false)
      printf("-1\n");
    else
      printf("%d\n", l);
  }
  return 0;
}
