#include <bits/stdc++.h>
using namespace std;
vector<int> poz[2];
char s[1000111];
int N, T, D, DD, Dmin, i, j, li, ls, mid, answer, p, q, pmax, cnt;
int ok(int k) {
  int kinit = k;
  Dmin = T + 1;
  D = 0;
  i = j = 0;
  p = 0;
  cnt = 0;
  while (i < poz[0].size()) {
    while (j < poz[1].size() && poz[1][j] < poz[0][i]) {
      k++;
      D += (poz[1][j] - p);
      p = poz[1][j];
      j++;
    }
    D += (poz[0][i] - p);
    p = poz[0][i];
    if (D >= Dmin) break;
    if (k > 0) {
      k--;
      i++;
    } else {
      int need_houses = poz[0].size() - i;
      if (j + (need_houses - 1) >= poz[1].size()) {
        D = 1000000001;
        break;
      }
      pmax = poz[0][poz[0].size() - 1];
      if (poz[1][j + need_houses - 1] > pmax)
        pmax = poz[1][j + need_houses - 1];
      if (D + 2 * (pmax - p) < Dmin) Dmin = D + 2 * (pmax - p);
      D += 2 * (poz[1][j] - p);
      j++;
      i++;
      while (i < poz[0].size() && j < poz[1].size()) {
        if (poz[0][i] < poz[1][j - 1]) {
          DD = 2 * (poz[1][j] - poz[1][j - 1]) + (poz[0][i] - poz[0][i - 1]);
          if (DD < (poz[0][i] - poz[0][i - 1]) + 2 * (poz[1][j] - poz[0][i])) {
            D += (poz[0][i] - poz[0][i - 1]);
            p = poz[0][i];
            need_houses = poz[0].size() - i;
            if (j + (need_houses - 1) < poz[1].size()) {
              pmax = poz[0][poz[0].size() - 1];
              if (poz[1][j + need_houses - 1] > pmax)
                pmax = poz[1][j + need_houses - 1];
              if (D + 2 * (pmax - poz[0][i]) < Dmin) Dmin = D + 2 * (pmax - p);
            }
            D += 2 * (poz[1][j] - poz[1][j - 1]);
            i++;
            j++;
          } else
            break;
        } else
          break;
      }
    }
  }
  if (D < Dmin) Dmin = D;
  if (Dmin <= T) return 1;
  return 0;
}
int main() {
  scanf("%d %d %s", &N, &T, s + 1);
  poz[0].clear();
  poz[1].clear();
  for (i = 1; i <= N; i++)
    if (s[i] == 'H')
      poz[0].push_back(i);
    else if (s[i] == 'S')
      poz[1].push_back(i);
  li = 0;
  ls = poz[0].size();
  if (poz[1].size() < poz[0].size()) li = poz[0].size() - poz[1].size();
  answer = -1;
  while (li <= ls) {
    mid = (li + ls) / 2;
    if (ok(mid)) {
      answer = mid;
      ls = mid - 1;
    } else {
      li = mid + 1;
    }
  }
  printf("%d\n", answer);
  return 0;
}
