#include <bits/stdc++.h>
using namespace std;
const int M = 500005;
int read() {
  int x = 0, f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9') {
    if (c == '-') f = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int n, m, ans = -1;
char s[M];
int check(int x) {
  int r = x, p = 0, t = 0, fl = 0, mi = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'H') r--, p = i;
    if (s[i] == 'S') {
      r++;
      if (r == 0) p = i;
    }
  }
  if (r < 0) return 0;
  for (int i = 1; i <= p; i++) {
    t++;
    if (s[i] == 'H') {
      x--;
      if (x == -1) {
        fl = i;
        mi = min(mi, t + 2 * (p - i));
      }
    }
    if (s[i] == 'S') {
      x++;
      if (x == 0) {
        t += 2 * (i - fl);
        fl = 0;
      }
    }
  }
  mi = min(mi, t);
  return mi <= m;
}
void dich(int l, int r) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  if (check(mid)) {
    ans = mid;
    dich(l, mid - 1);
  } else
    dich(mid + 1, r);
}
signed main() {
  n = read();
  m = read();
  scanf("%s", s + 1);
  dich(0, n);
  printf("%d\n", ans);
}
