#include <bits/stdc++.h>
const int MOD = 1E9 + 7;
const int N = 5000000 + 5;
const int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
using namespace std;
int n, t;
string str;
int numH;
int check(int mid, int step) {
  int cnt = 0;
  int pos1 = -1, pos2 = 0, sub = 0;
  for (int i = 0; i < n; i++) {
    if (cnt == numH && mid >= 0) {
      if (step >= min(i - pos1, sub))
        return true;
      else
        return false;
    }
    step--;
    if (str[i] == 'H') {
      if (mid == 0) {
        if (pos1 == -1) pos1 = i;
        pos2 = i;
      }
      mid--;
      cnt++;
    } else if (str[i] == 'S') {
      mid++;
      if (mid == 0) {
        sub += i - pos2;
        if (cnt != numH) sub += i - pos2;
      }
    }
  }
  if (step >= min(n - 1 - pos1, sub) && mid >= 0)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &n, &t);
  cin >> str;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'H') numH++;
  }
  int left = 0, right = numH;
  while (left < right) {
    int mid = (left + right) >> 1;
    if (check(mid, t))
      right = mid;
    else
      left = mid + 1;
  }
  if (check(left, t))
    printf("%d\n", left);
  else
    printf("-1\n");
  return 0;
}
