#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
int N, T, S, H;
char str[maxn];
int rx[maxn], ry[maxn];
bool _check(int K) {
  int i, j, k, h, R;
  long long t, tt;
  j = -1;
  k = K;
  h = H;
  R = 0;
  t = 0;
  if (h == 0) return true;
  for (i = 1; i <= N; i++) {
    t++;
    if (str[i] == 'S') {
      k++;
      if (k == 0) {
        if (h == 0) {
          t += i - j;
          i = j;
          break;
        } else {
          ++R;
          rx[R] = j;
          ry[R] = i;
          t += (i - j) * 2;
        }
      }
    } else if (str[i] == 'H') {
      k--;
      h--;
      if (k == -1) j = i;
      if (h == 0 && k >= 0) break;
    }
  }
  j = i;
  tt = 0;
  for (i = R; i >= 1; i--) {
    tt += (j - ry[i]) - (ry[i] - rx[i]);
    j = rx[i];
    if (tt < 0) t += tt;
  }
  return t <= T;
}
int main() {
  int i, l, r, mid;
  scanf("%d%d", &N, &T);
  scanf("%s", str + 1);
  for (i = 1; i <= N; i++) {
    S += str[i] == 'S';
    H += str[i] == 'H';
  }
  l = S >= H ? 0 : H - S;
  r = N + 1;
  while (l < r) {
    mid = (l + r) >> 1;
    if (_check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l <= N ? l : -1);
  return 0;
}
