#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int min_time(int k) {
  int kcur = k;
  int cur_need = 0;
  int min_need = -1;
  int run_out = 0;
  vector<int> start;
  vector<int> end;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      run_out = i;
      if (kcur != 0) {
        kcur--;
      } else {
        if (cur_need == 0) {
          start.push_back(i);
          min_need = i;
        }
        cur_need++;
      }
    } else if (s[i] == 'S') {
      kcur++;
      {
        if (kcur == cur_need) {
          end.push_back(i);
          kcur = 0;
          cur_need = 0;
          min_need = -1;
        }
      }
    }
  }
  if (start.empty()) {
    return run_out + 1;
  }
  if (end[end.size() - 1] < run_out) {
    start.push_back(run_out);
    end.push_back(run_out);
  }
  int tcur = 2 * end[end.size() - 1] - start[0] + 1;
  int csum = tcur;
  for (int i = 0; i < start.size() - 1; i++) {
    csum += end[i] - start[i];
    csum -= start[i + 1] - end[i];
    tcur = min(csum, tcur);
  }
  return tcur;
}
int main() {
  cin >> n >> t;
  cin >> s;
  int nh = 0;
  int ns = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'H') {
      nh++;
    } else if (s[i] == 'S') {
      ns++;
    }
  }
  int lo = max(nh - ns, 0);
  int hi = nh;
  int best = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int nt = min_time(mid);
    if (nt <= t) {
      best = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << best;
}
