#include <bits/stdc++.h>
using namespace std;
const int MAX = 500100;
char s[MAX];
int main() {
  int n, t;
  scanf("%d%d%s", &n, &t, s);
  int l = -1, r = MAX;
  while (r - l > 1) {
    int k = (l + r + 1) / 2;
    vector<pair<int, int> > prs;
    int cur_t = 0, last_t = 0, cur_k = k, last_i = 0, need = 0, real_last = 0;
    for (int i = 0; i < n; ++i) {
      cur_t++;
      if (s[i] == 'S') {
        cur_k++;
        if (need && cur_k >= need) {
          real_last = i;
          cur_k -= need;
          need = 0;
          cur_t += (i - last_i) * 2;
          last_t = cur_t;
          prs.push_back(make_pair(last_i, (i - last_i) * 2));
        }
      } else if (s[i] == 'H') {
        if (cur_k) {
          cur_k--;
          last_t = cur_t;
          real_last = i;
        } else if (need) {
          need++;
        } else {
          need = 1;
          last_i = i;
        }
      }
    }
    if (!need) {
      int sums = 0;
      int old_last_t = last_t;
      for (int i = prs.size() - 1; i >= 0; --i) {
        sums += prs[i].second;
        last_t = min(last_t, old_last_t - sums + real_last - prs[i].first);
      }
    }
    if (need || last_t > t)
      l = k;
    else
      r = k;
  }
  if (r == MAX)
    printf("-1\n");
  else
    printf("%d\n", r);
  return 0;
}
