#include <bits/stdc++.h>
using namespace std;
const int MAXL = 5e5 + 1e3;
int n, t;
char dat[MAXL + 1];
int main() {
  int n;
  while (scanf("%d%d%s", &n, &t, dat) >= 1) {
    int hl = n, hr = -1, hcnt = 0;
    vector<int> shops;
    for (int i = 0; i < n; i++)
      if (dat[i] == 'H') {
        hl = min(hl, i);
        hr = max(hr, i);
        hcnt++;
      } else if (dat[i] == 'S') {
        shops.push_back(i);
      }
    t--;
    if (hr > t)
      printf("-1\n");
    else {
      int L = -1, R = hcnt;
      while (L + 1 < R) {
        int M = (L + R) / 2;
        assert(M < hcnt);
        bool good = false;
        int rem = hcnt - M;
        if (rem <= ((int)(shops).size())) {
          int maxpos = max(hr, shops[rem - 1]);
          int ctim = maxpos;
          int btim = 2e9;
          int bal = M;
          for (int i = 0; i <= maxpos; i++) {
            if (dat[i] == 'H')
              bal--;
            else if (dat[i] == 'S')
              bal++;
            if (bal < 0) {
              btim = min(btim, ctim + maxpos - i);
              ctim += 2;
            }
          }
          btim = min(btim, ctim);
          if (btim <= t) good = true;
        }
        if (good)
          R = M;
        else
          L = M;
      }
      printf("%d\n", R);
    }
  }
  return 0;
}
