#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N, T;
  string S;
  cin >> N >> T >> S;
  T--;
  int lastH = -1, pH = 0;
  for (int i = 0; i < N; i++)
    if (S[i] == 'H') lastH = i, pH++;
  if (lastH > T) {
    cout << "-1\n";
    return 0;
  }
  int tA = -1, tB = N + 1;
  while (tB - tA > 1) {
    int t = (tB + tA) / 2;
    int lastP = lastH, sh = 0;
    for (int i = 0; i < N; i++)
      if (S[i] == 'S') {
        sh++;
        if (sh + t <= pH) lastP = max(lastP, i);
      }
    if (sh + t < pH) {
      tA = t;
      continue;
    }
    int akt = t, lastHx = N + 1, pHx = 0, tt = 0;
    bool ok = false;
    for (int i = 0; i <= lastP; i++) {
      if (S[i] == 'S') {
        akt++;
        if (lastHx != N + 1 && pHx <= akt) {
          if (tt + 2 * lastP - lastHx <= T) ok = true;
          tt += 2 * (i - lastHx);
          akt -= pHx;
          pHx = 0;
          lastHx = N + 1;
        }
      }
      if (S[i] == 'H') {
        if (akt > 0)
          akt--;
        else {
          if (lastHx == N + 1) lastHx = i;
          pHx++;
        }
      }
      if (tt + 2 * lastP - min(i, lastHx) <= T) ok = true;
    }
    if (ok)
      tB = t;
    else
      tA = t;
  }
  cout << tB << "\n";
  return 0;
}
