#include <bits/stdc++.h>
void fileio_in_out() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
void fileio_txt() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int n, t, house = 0, lasthouse = 0, ans = -1;
int i, j, k, l;
char s[1111111];
int a[1111111], f[1111111];
int check(int k) {
  int i, j = 0, mint = 0, ret = (1e9), stop = lasthouse, tmp = k;
  f[0] = k;
  for (i = 1; i <= n; i++) {
    f[i] = a[i] + k;
    if (s[i] == 'S') tmp++;
    if (s[i] != '.' && tmp == house) stop = (((stop) > (i)) ? (stop) : (i));
  }
  if (tmp < house) return 0;
  for (i = 1; i <= lasthouse; i++) {
    mint++;
    if (s[i] == 'H' && f[i] == -1) {
      j = i;
      while (f[j] != 0) j++;
      ret =
          (((ret) < (mint + (stop - i) * 2)) ? (ret) : (mint + (stop - i) * 2));
      mint += 3 * (j - i);
      i = j;
    }
  }
  ret = (((ret) < (mint)) ? (ret) : (mint));
  return (ret <= t);
}
int erfen(int x, int y) {
  int mid = (x + y) / 2;
  if (x == y) return x;
  if (check(mid))
    return erfen(x, mid);
  else
    return erfen(mid + 1, y);
}
int main() {
  scanf("%d%d%s", &n, &t, s + 1);
  a[0] = 0;
  for (i = 1; i <= n; i++) {
    a[i] = a[i - 1];
    if (s[i] == 'H') {
      a[i]--;
      house++;
      lasthouse = i;
    }
    if (s[i] == 'S') a[i]++;
  }
  if (t >= lasthouse) ans = erfen(0, n);
  printf("%d\n", ans);
  return 0;
}
