#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <typename X>
inline bool minimize(X& p, X q) {
  if (p <= q) return 0;
  p = q;
  return 1;
}
template <typename X>
inline bool maximize(X& p, X q) {
  if (p >= q) return 0;
  p = q;
  return 1;
}
char str[500005];
int main() {
  int N, T;
  vector<int> pH, pS;
  scanf("%d%d%s", &N, &T, str + 1);
  for (int i = 1; i <= N; ++i) {
    if (str[i] == 'H')
      pH.push_back(i);
    else if (str[i] == 'S')
      pS.push_back(i);
  }
  if (pH.back() > T) {
    printf("-1\n");
    return 0;
  }
  int nH = pH.size(), nS = pS.size();
  int L = max(0, nH - nS), R = nH;
  while (L != R) {
    int mid = (L + R) >> 1;
    int ans = INF, sum = 0, endpoint = max(pH.back(), pS[nH - mid - 1]),
        pos = pH[mid];
    for (int i = mid; i < nH; ++i) {
      minimize(ans, sum + endpoint - pH[i]);
      if (pS[i - mid] < pH[i])
        pos = pH[i];
      else {
        sum += (pS[i - mid] - max(pos, pH[i])) << 1;
        pos = pS[i - mid];
      }
    }
    minimize(ans, sum);
    if (ans + endpoint <= T)
      R = mid;
    else
      L = mid + 1;
  }
  printf("%d\n", L);
  return 0;
}
