#include <bits/stdc++.h>
using namespace std;
char S[500005];
int A[500005], B[500005];
int CH, CS;
int N, T;
bool go(int K) {
  if (K + CS < CH) return 0;
  if (2 * N <= T) return 1;
  if (K >= CH) return A[CH - 1] + 1 <= T;
  int t = 0, k = K, mn = 1 << 30, h = 0;
  int lh = A[CH - 1], ls = B[CH - K - 1];
  for (int i = 0; i < N && h < CH; ++i) {
    t++;
    if (S[i] == 'S') k++;
    if (S[i] == 'H') {
      ++h;
      if (!k) {
        mn = min(mn, t + 2 * (max(lh, ls) - i));
        int b = 1, j = i;
        while (b) {
          ++j;
          if (S[j] == 'S') --b;
          if (S[j] == 'H') ++b, ++h;
        }
        t += 3 * (j - i);
        i = j;
      } else
        k--;
    }
  }
  mn = min(t, mn);
  return mn <= T;
}
int main() {
  scanf("%d%d%s", &N, &T, S);
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'H') A[CH++] = i;
    if (S[i] == 'S') B[CS++] = i;
  }
  int s = 0, e = N, ans = -1;
  while (s <= e) {
    int m = (s + e) / 2;
    if (go(m))
      ans = m, e = m - 1;
    else
      s = m + 1;
  }
  printf("%d", ans);
  return 0;
}
