#include <bits/stdc++.h>
int n, m;
char s[1000000];
int ll[1000000], rr[1000000];
bool gao(int st) {
  int num = st, ti, p = 0, last, t1, t2;
  for (int i = 0; i <= n - 1; i++) {
    if (s[i] == '.') continue;
    if (s[i] == 'H') {
      num--;
      if (num == -1) {
        p++;
        ll[p] = i;
      }
      last = i;
    }
    if (s[i] == 'S') {
      num++;
      if (num == 0) {
        rr[p] = i;
        last = i;
      }
    }
  }
  if (p >= 1) {
    p++;
    ll[p] = last;
    rr[p] = last;
    while (p > 1) {
      t1 = 2 * (rr[p - 1] - ll[p - 1]) + (rr[p] - ll[p]);
      t2 = rr[p] - ll[p - 1];
      if (t1 >= t2) {
        p--;
        rr[p] = rr[p + 1];
      } else
        break;
    }
  }
  ti = last + 1;
  for (int i = 1; i <= p - 1; i++) ti += 2 * (rr[i] - ll[i]);
  ti += rr[p] - ll[p];
  if (num < 0 || ti > m) return false;
  return true;
}
int main() {
  int l, r, mid, ans;
  scanf("%d%d", &n, &m);
  scanf("%s", s);
  l = 0;
  r = m;
  ans = -1;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (gao(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
}
