#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 500010;
int n, k;
char str[max_n + 5];
int P[max_n], nP;
int S[max_n], nS;
pair<int, int> Q[max_n];
int nQ;
bool possible(int a) {
  int right = -1;
  for (int p = 0; p < a; ++p) right = max(right, P[p]);
  nQ = 0;
  for (int p = a; p < nP; ++p) {
    int s = p - a;
    right = max(right, P[p]);
    right = max(right, S[s]);
    if (S[s] > P[p]) Q[nQ++] = pair<int, int>(P[p], S[s]);
  }
  if (nQ == 0) return (right + 1 <= k);
  int best = right + 1 + (right - Q[0].first);
  int toadd = 0;
  for (int i = 0; i < nQ; ++i) {
    if (i == 0)
      toadd += 2 * (Q[i].second - Q[i].first);
    else
      toadd += 2 * (Q[i].second - max(Q[i - 1].second, Q[i].first));
    if (i + 1 < nQ)
      best = min(best, right + 1 + toadd + (right - Q[i + 1].first));
    else
      best = min(best, right + 1 + toadd);
  }
  return (best <= k);
}
int main() {
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%s", str);
  nP = 0;
  nS = 0;
  for (int i = 0; i < n; ++i) {
    if (str[i] == 'H')
      P[nP++] = i;
    else if (str[i] == 'S')
      S[nS++] = i;
  }
  if (not possible(nP))
    printf("%d\n", -1);
  else {
    int l = max(nP - nS, 0) - 1, r = nP;
    while (l + 1 < r) {
      int mid = (l + r) / 2;
      if (possible(mid))
        r = mid;
      else
        l = mid;
    }
    printf("%d\n", r);
  }
  return 0;
}
