#include <bits/stdc++.h>
using namespace std;
char a[500000 + 10];
int n, t;
int mh;
int h, s;
int go(int mid) {
  int num = mid;
  int cnt = 0;
  int en = mh;
  int last;
  if (mid < h) {
    int u = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 'S') {
        u++;
        if (u == h - mid) {
          en = max(en, i);
          break;
        }
      }
    }
  }
  for (int i = 0; i <= en; i++) {
    cnt++;
    if (a[i] == 'H') {
      num--;
      if (num == -1) {
        if (cnt + (en - i) * 2 <= t) return 1;
        last = i;
      }
    } else if (a[i] == 'S') {
      num++;
      if (num == 0) cnt += (i - last) * 2;
    }
  }
  if (cnt <= t)
    return 1;
  else
    return 0;
}
int main() {
  while (scanf("%d %d", &n, &t) != EOF) {
    scanf("%s", a);
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == 'H') {
        mh = i;
        break;
      }
    }
    if (mh + 1 > t) {
      printf("-1\n");
      continue;
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == 'H')
        h++;
      else if (a[i] == 'S')
        s++;
    }
    int l = max(0, h - s), r = h;
    int mid;
    while (l < r) {
      mid = (l + r) / 2;
      if (go(mid))
        r = mid;
      else
        l = mid + 1;
    }
    printf("%d\n", l);
  }
}
