#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool RD(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 0;
}
template <class T>
inline void Put(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) Put(x / 10);
  putchar(x % 10 + '0');
}
const int N = 5e5 + 100;
int n, lim, MAX;
int sum[N];
int a[N];
char s[N];
bool Check(int x, int maxx) {
  int cnt = x;
  int cur = 0;
  int tmp = 1000000000;
  int pos, last = 0;
  for (int i = 1; i <= int(n); i++) {
    if (s[i] == 'H')
      cnt--;
    else if (s[i] == 'S')
      cnt++;
    if (cnt == 0 && last == -1) maxx = max(maxx, i);
    last = cnt;
  }
  cnt = x, last = 0;
  for (int i = 1; i <= maxx; i++) {
    cur++;
    if (s[i] == 'H')
      cnt--;
    else if (s[i] == 'S')
      cnt++;
    if (last == 0 && cnt == -1) {
      tmp = min(tmp, cur + 2 * (maxx - i));
      pos = i;
    }
    if (last == -1 && cnt == 0) {
      cur += 2 * (i - pos);
    }
    last = cnt;
  }
  return min(tmp, cur) <= lim;
}
int main() {
  scanf("%d%d%s", &n, &lim, s + 1);
  int ch = 0, cs = 0;
  for (int i = 1; i <= int(n); i++) {
    if (s[i] == 'H')
      MAX = i, ch++;
    else if (s[i] == 'S')
      cs++;
  }
  int lb = max(0, ch - cs) - 1;
  int ub = 1000000000;
  if (MAX > lim) {
    puts("-1");
    return 0;
  }
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (Check(mid, MAX))
      ub = mid;
    else
      lb = mid;
  }
  printf("%d\n", ub);
}
