#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 100000;
const int INF = 2000000000;
int N, T;
char inp[MAXN + 10];
int houses;
bool can(int K) {
  int endShop = -1;
  int curShops = 0;
  int curHouses = 0;
  for (int i = 0; i < N; i++) {
    if (inp[i] == 'S') curShops++;
    if (inp[i] == 'H') curHouses++;
    if (K + curShops == houses && curHouses == houses) {
      endShop = i;
      break;
    }
  }
  int bestTime = INF;
  int curTime = 0;
  int visH = 0;
  int have = K;
  int bad = -1;
  int miss = 0;
  for (int i = 0; i < N; i++) {
    curTime++;
    if (inp[i] == 'S') {
      if (have == -1) {
        visH += miss;
        curTime += i - bad;
        if (visH == houses) {
          bestTime = min(bestTime, curTime);
          break;
        }
        curTime += i - bad;
        bad = -1;
        have++;
        miss = 0;
        continue;
      }
      have++;
    }
    if (inp[i] == 'H') {
      if (have > 0) {
        have--;
        visH++;
      } else {
        miss++;
        if (have == 0) {
          if (endShop != -1)
            bestTime = min(bestTime, curTime + 2 * (endShop - i));
        }
        if (bad == -1) bad = i;
        have--;
      }
    }
    if (visH == houses) bestTime = min(bestTime, curTime);
  }
  return bestTime <= T;
}
int main() {
  cin >> N >> T;
  cin >> inp;
  for (int i = 0; i < N; i++)
    if (inp[i] == 'H') houses++;
  int ans = -1;
  int leftK = 0, rightK = houses;
  while (leftK <= rightK) {
    int midK = (leftK + rightK) / 2;
    if (can(midK)) {
      ans = midK;
      rightK = midK - 1;
    } else {
      leftK = midK + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
