#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const double PI = acos(-1.0);
const int oo = 1 << 29;
const int N = 101111 * 5;
int n, ot, mxh;
char s[N];
int judge(int m) {
  int t = ot - mxh;
  int x = m;
  int j = -10000000;
  int lasd = -1, las0 = -1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'S') {
      x++;
      if (x == 0) {
        if (i < mxh) {
          t -= 2 * (i - j);
          lasd = i - j;
          las0 = i;
        } else {
          t -= i - j + i - mxh;
          if (i > mxh) {
            int nowd = i - las0;
            if (nowd < lasd) t += lasd - nowd;
          }
        }
      }
    } else if (s[i] == 'H') {
      x--;
      if (x == -1) j = i;
      if (i == mxh && x >= 0) {
        int nowd = i - las0;
        if (nowd < lasd) t += lasd - nowd;
      }
    }
  }
  if (t < 0 || x < 0) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &ot);
  scanf("%s", s + 1);
  mxh = n;
  while (s[mxh] != 'H') mxh--;
  if (ot - mxh < 0) {
    puts("-1");
    return 0;
  }
  int l = 0, r = N, ans = -1;
  while (l <= r) {
    int m = (l + r) / 2;
    if (judge(m)) {
      ans = m;
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
