#include <bits/stdc++.h>
using namespace std;
int n, t, tot1, tot2;
char a[500005];
bool check(int tot, int t1) {
  int cnt = 0, pos1 = -1, pos2 = 0, tx = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt == tot1 && tot >= 0) {
      if (t1 >= min(i - pos1, tx))
        return 1;
      else
        return 0;
    }
    t1--;
    if (a[i] == 'H') {
      if (tot == 0) {
        if (pos1 == -1) pos1 = i;
        pos2 = i;
      }
      tot--;
      cnt++;
    }
    if (a[i] == 'S') {
      tot++;
      if (tot == 0) {
        tx += i - pos2;
        if (cnt != tot1) tx += i - pos2;
      }
    }
  }
  if (t1 >= min(n - pos1, tx) && tot >= 0)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d%d\n", &n, &t);
  for (int i = 1; i <= n; i++) {
    scanf("%c", &a[i]);
    if (a[i] == 'H')
      tot1++;
    else
      tot2++;
  }
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid, t))
      r = mid;
    else
      l = mid + 1;
  }
  if (check(l, t))
    printf("%d\n", l);
  else
    printf("-1\n");
}
