#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 22;
int n, t, h;
char st[maxn], s[maxn];
bool yes(int k) {
  int tim = 0, candy = k, home = h;
  int i, p, q;
  for (i = 1, p = 0, q = 0; i <= n; ++i) {
    p += s[i] == 'H';
    q += s[i] == 'S';
    if (p == h && k + q >= h) break;
  }
  if (!(p == h && k + q >= h)) return false;
  if (i * 2 - 1 <= t) return true;
  for (i = 1; i <= n; ++i) {
    if (!home) return tim <= t;
    if (++tim > t) return false;
    if (s[i] == 'S') ++candy;
    if (s[i] == 'H') {
      if (candy) {
        --candy;
        --home;
        continue;
      }
      int hh = 0, miao = 0, j;
      for (j = i; j <= n; ++j) {
        if (s[j] == 'H') {
          ++miao;
          ++hh;
        }
        if (s[j] == 'S') {
          --miao;
          s[j] = '.';
        }
        if (miao == 0) break;
      }
      if (miao) return false;
      tim += 2 * (j - i);
      candy += hh;
      --i;
      --tim;
    }
  }
  return tim <= t;
}
int main() {
  scanf("%d%d", &n, &t);
  scanf("%s", st + 1);
  for (int i = 1; i <= n; ++i) h += st[i] == 'H';
  int l = 0, r = n, ans = -1;
  while (l <= r) {
    int mid = (l + r + 1) / 2;
    memcpy(s, st, sizeof(s));
    if (yes(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
