#include <bits/stdc++.h>
using namespace std;
int N, T, H, S, lo, hi, mid, candy[500005];
vector<int> V;
vector<pair<int, int> > range;
char str[500005];
int dist(pair<int, int> x) { return x.second - x.first; }
bool can(int x) {
  int pre, cur = x, it = 0, tm = 0, best, tmp = 0, max_end = 0;
  V.clear();
  range.clear();
  memset(candy, 0, sizeof(candy));
  for (int i = 1; i <= N; ++i) {
    if (str[i] == 'S') ++cur;
    while (cur > 0 && it < V.size()) {
      tm = i;
      max_end = i;
      --cur;
      candy[V[it++]] = i;
    }
    if (str[i] == 'H') {
      tm = i;
      max_end = i;
      if (cur > 0)
        --cur;
      else
        V.push_back(i);
    }
  }
  pre = cur = 0;
  for (int i = 0; i < V.size(); ++i) {
    if (V[i] > cur) {
      if (pre > 0) range.push_back(pair<int, int>(pre, cur));
      pre = V[i];
      cur = candy[V[i]];
    } else
      cur = candy[V[i]];
  }
  range.push_back(pair<int, int>(pre, cur));
  for (int i = 0; i < range.size(); ++i) tmp += 2 * dist(range[i]);
  best = tmp;
  if (range.size() > 0)
    tmp += max_end - range[range.size() - 1].second -
           dist(range[range.size() - 1]);
  if (tmp < best) best = tmp;
  for (int i = range.size() - 2; i >= 0; --i) {
    tmp = tmp - dist(range[i]) + range[i + 1].first - range[i].second;
    if (tmp < best) best = tmp;
  }
  return tm + best <= T;
}
int main() {
  scanf("%d%d %s", &N, &T, str + 1);
  for (int i = 1; i <= N; ++i) {
    H += str[i] == 'H';
    S += str[i] == 'S';
  }
  lo = max(0, H - S);
  hi = H;
  while (hi > lo) {
    mid = (hi + lo) / 2;
    if (can(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  if (can(hi))
    printf("%d\n", hi);
  else
    printf("-1\n");
}
