#include <bits/stdc++.h>
using namespace std;
int N, T;
string road;
int main() {
  cin >> N >> T >> road;
  int best = 1e9;
  vector<int> hpos, spos, ord(N, -1), hst;
  for (int i = 0; i < int(N); ++i)
    if (road[i] == 'H')
      hpos.push_back(i);
    else if (road[i] == 'S')
      spos.push_back(i);
  for (int i = 0; i < int(hpos.size()); ++i) ord[hpos[i]] = i;
  for (int i = 0; i < int(spos.size()); ++i) ord[spos[i]] = i;
  int left = max(0, (int)hpos.size() - (int)spos.size());
  int right = hpos.size();
  while (left <= right) {
    int kilo = left + (right - left) / 2, mid = kilo;
    int time = 0, success = 0;
    int hpass = 0, spass = 0;
    hst.clear();
    int last = max(hpos.back(),
                   (kilo == hpos.size() ? 0 : spos[hpos.size() - 1 - kilo]));
    for (int i = 0; i < int(N); ++i) {
      time++;
      if (hpass < hpos.size() && hst.size() == 0 &&
          time + last - i + last - hpos[hpass] <= T)
        success = 1;
      if (road[i] == 'H') {
        if (!kilo)
          hst.push_back(i);
        else
          kilo--;
        hpass++;
      }
      if (road[i] == 'S') {
        if (hst.size() == 1) {
          int dist = i - hst.back();
          if (i > hpos.back())
            time += dist;
          else
            time += 2 * dist;
        }
        if (hst.size()) {
          hst.pop_back();
        } else
          kilo++;
        spass++;
      }
      if (i >= last && time <= T) success = 1;
    }
    if (!success)
      left = mid + 1;
    else {
      best = min(best, mid);
      right = mid - 1;
    }
  }
  cout << (best < 1e9 ? best : -1) << endl;
}
