#include <bits/stdc++.h>
int Shop[510000], ShopT, Home[510000], HomeT, a[510000], Now[510000], L, R, n,
    T;
int Max(int a, int b) { return a > b ? a : b; }
bool Check(int M) {
  int i, LastPlace, NowNeed, Last, BL, LastShop, Sum;
  if (M >= HomeT) return Home[HomeT - 1] + 1 <= T;
  if (ShopT + M < HomeT) return 0;
  LastPlace = Max(Home[HomeT - 1], Shop[HomeT - M - 1]);
  NowNeed = HomeT - M;
  for (i = 0; i < NowNeed; i++) Now[i] = Home[M + i] <= Shop[i];
  Sum = LastPlace + 1;
  BL = 0;
  i = M;
  for (Last = 0; Last <= LastPlace; Last++) {
    if (Sum + LastPlace - Last <= T) return 1;
    if (Sum > T) return 0;
    for (; i < HomeT && Home[i] <= Last; i++)
      if (Now[i - M] == 1) {
        if (BL) {
          Sum += 2 * (Shop[i - M] - LastShop);
          LastShop = Shop[i - M];
        } else {
          BL = 1;
          LastShop = Shop[i - M];
          Sum += 2 * (Shop[i - M] - Home[i]);
        }
      } else
        BL = 0;
  }
  return 0;
}
int main() {
  int i, j;
  scanf("%d%d\n", &n, &T);
  for (i = 0; i < n; i++) {
    j = getchar();
    if (j == 'H') {
      a[i] = 1;
      Home[HomeT++] = i;
    } else if (j == 'S') {
      a[i] = 2;
      Shop[ShopT++] = i;
    } else
      a[i] = 0;
  }
  L = -1;
  R = n + 1;
  Check(1);
  for (; L + 1 < R;)
    if (Check((L + R) / 2))
      R = (L + R) / 2;
    else
      L = (L + R) / 2;
  if (R == n + 1)
    printf("-1\n");
  else
    printf("%d\n", R);
  return 0;
}
