#include <bits/stdc++.h>
const int N = 1000100;
char s[N];
int n, t;
int ok(int candy) {
  int candytmp = candy;
  int ans = 1 << 30;
  int tim = 0;
  int end = 0;
  int len = 0;
  bool neg = false;
  int in = -1, out = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      candytmp--;
      len = i;
    }
    if (s[i] == 'S') {
      candytmp++;
      if (candytmp <= 0) len = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') candy--;
    if (s[i] == 'S') candy++;
    if (candy < 0 && !neg) {
      neg = true, in = i;
      int tmp = len + 1 + len - in + tim;
      if (tmp < ans) ans = tmp;
    }
    if (candy == 0 && neg) {
      neg = false, tim += 2 * (i - in);
    }
  }
  int tmp = len + 1 + tim;
  if (tmp < ans) ans = tmp;
  if (neg) return -1;
  if (in == -1)
    return len + 1;
  else
    return ans;
}
int main() {
  while (~scanf("%d %d", &n, &t)) {
    scanf("%s", s);
    int ans;
    int len = 0;
    for (int i = 0; i < n; i++)
      if (s[i] == 'H') len = i + 1;
    if (len > t) {
      puts("-1");
      continue;
    }
    int h = 0, e = n;
    while (e - h > 1) {
      int mid = (e + h) / 2;
      int tmp = ok(mid);
      if (tmp == -1 || tmp > t)
        h = mid;
      else
        e = mid;
    }
    int tmp = ok(h);
    if (tmp != -1 && tmp <= t) e = h;
    printf("%d\n", e);
  }
}
