#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
char s[500005];
int tag[500005];
int n, limit, tot = 0;
bool judge(int more) {
  int last, cpy = more;
  int f = 0;
  for (last = 1; last <= n; ++last) {
    if (s[last] == 'H')
      f++;
    else if (s[last] == 'S')
      cpy++;
    if (cpy >= f && f == tot) break;
  }
  if (last == n + 1) return 0;
  memset(tag, 0, sizeof(tag));
  int size = 0, pos = -1, t = 0;
  for (register int i = (1); i <= int(last); ++i) {
    ++t;
    if (s[i] == 'H') {
      if (more)
        more--;
      else {
        size++;
        if (pos == -1) pos = i;
      }
    } else if (s[i] == 'S') {
      more++;
      if (size && more >= size) {
        tag[pos] = (i - pos) << 1;
        t += tag[pos];
        more -= size;
        size = 0;
        pos = -1;
      }
    }
  }
  int res = t;
  for (register int i = (last); i >= int(0); --i) {
    if (s[i] == 'H') t -= tag[i];
    res = min(res, t);
    ++t;
  }
  return res <= limit;
}
int main() {
  n = read(), limit = read();
  scanf("%s", s + 1);
  for (register int i = (1); i <= int(n); ++i) tot += s[i] == 'H';
  if (!judge(n)) {
    puts("-1");
    return 0;
  }
  int l = 0, r = n, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (judge(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  writeln(ans);
}
