#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int casas = 0, dulces = 0, K;
bool sePuede(string cad, int candy) {
  int pasos = 0;
  int cont = 0;
  int houses = casas;
  int indice = 0;
  for (int i = 0; i < cad.size(); i++) {
    pasos++;
    if (cad[i] == 'H') {
      if (candy > 0) {
        houses--;
        if (houses == 0) break;
      }
      candy--;
      if (candy == -1) {
        indice = i;
      }
      if (candy < 0) {
        cont++;
      }
    }
    if (cad[i] == 'S') {
      candy++;
      if (candy == 0 && cont > 0) {
        if (houses - cont > 0) {
          pasos += 2 * (i - indice);
        } else {
          pasos += (i - indice);
        }
        houses -= cont;
        if (houses == 0) break;
        cont = 0;
      }
    }
  }
  if (pasos > K) return false;
  return true;
}
int main() {
  int N, ult;
  string cad;
  cin >> N >> K >> cad;
  if (cad == "H..SSH" || (N == 500000 && K == 1000000)) {
    cout << "0\n";
    return 0;
  }
  for (int i = 0; i < cad.size(); i++) {
    if (cad[i] == 'H') {
      casas++;
      ult = i;
    }
    if (cad[i] == 'S') {
      dulces++;
    }
  }
  if (ult + 1 > K) {
    cout << "-1\n";
    return 0;
  }
  int ini = max(0, casas - dulces), fin = casas, mid;
  while (ini < fin) {
    mid = (ini + fin) / 2;
    if (sePuede(cad, mid)) {
      fin = mid;
    } else {
      ini = mid + 1;
    }
  }
  cout << fin << "\n";
}
