#include <bits/stdc++.h>
using namespace std;
int n, t, sum, maxh;
char s[5 * 100010];
int solve(int m) {
  int v = m;
  long long tt = 0;
  for (int i = 0; i <= maxh; i++) {
    tt++;
    if (s[i] == 'H') v--;
    if (s[i] == 'S') v++;
    if (v < 0) {
      for (int j = i + 1; j < n; j++) {
        if (s[j] == 'H') v--;
        if (s[j] == 'S') v++;
        if (v == 0) {
          if (j > maxh)
            tt += (long long)(j - i) * 2;
          else
            tt += (long long)(j - i) * 3;
          i = j;
          break;
        }
      }
      if (v < 0) return 0;
    }
  }
  if (tt <= t) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &t);
  scanf("%s", s);
  sum = 0, maxh = -1;
  for (int i = 0; i < n; i++)
    if (s[i] == 'H') {
      maxh = i;
    } else if (s[i] == 'S')
      sum++;
  if (maxh == -1) {
    printf("0\n");
    return 0;
  }
  int v = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == 'H')
      v--;
    else if (s[i] == 'S')
      v++;
  if (v >= 0 && 1 + 2 * (n - 1) <= t) {
    printf("0\n");
    return 0;
  }
  int l = 0, r = n + 10;
  while (l < r) {
    int m = (l + r) >> 1;
    int t = solve(m);
    if (t)
      r = m;
    else
      l = m + 1;
  }
  if (l > n)
    printf("-1\n");
  else
    printf("%d\n", l);
  return 0;
}
