#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
const int MAXN = 500010;
char str[MAXN];
long long N, T, H, S;
bool judge(int mid) {
  int prepos = -1, sum = mid;
  int last = 0;
  for (int i = 1; i <= N; i++) {
    if (str[i] == 'H') {
      sum--;
      last = i;
    } else if (str[i] == 'S') {
      sum++;
      if (sum == 0) {
        last = i;
      }
    }
  }
  if (sum < 0) return false;
  int ti = 0;
  sum = mid;
  for (int i = 1; i <= last; i++) {
    ti++;
    if (str[i] == 'H') {
      sum--;
      if (sum == -1) {
        if (ti + (last - i) * 2 <= T) return true;
        prepos = i;
      }
    } else if (str[i] == 'S') {
      sum++;
      if (sum == 0) {
        if (prepos != -1) {
          ti += (i - prepos) * 2;
          prepos = -1;
        }
      }
    }
  }
  return ti <= T;
}
int main() {
  while (scanf("%I64d%I64d", &N, &T) != EOF) {
    scanf("%s", str + 1);
    H = 0;
    S = 0;
    for (int i = 1; i <= N; i++) {
      if (str[i] == 'H')
        H++;
      else if (str[i] == 'S')
        S++;
    }
    int L = max(0LL, H - S), R = H;
    int ans = -1;
    while (L <= R) {
      int mid = (L + R) / 2;
      if (judge(mid)) {
        ans = mid;
        R = mid - 1;
      } else
        L = mid + 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
