#include <bits/stdc++.h>
using namespace std;
int n, t;
int ult, casas;
string s;
int solve(int k) {
  int u = -1;
  int acc = k;
  for (int i = 0; i < n; i++)
    if (s[i] == 'S') {
      acc++;
      if (acc >= casas) {
        u = i;
        break;
      }
    }
  if (u == -1) return 2000000000;
  u = max(u, ult);
  acc = k;
  int last = 2000000000;
  int t = 1, need = 0;
  int ans = 2000000000;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      if (acc) {
        acc--;
        if (i == ult && need == 0) ans = min(ans, t);
      } else {
        last = min(last, i);
        need++;
      }
      t++;
    } else if (s[i] == 'S') {
      acc++;
      if (need && acc >= need) {
        ans = min(ans, t + 2 * (u - i) + (i - last));
        acc -= need;
        need = 0;
        if (i >= ult) {
          t += (i - last);
          ans = min(ans, t);
          return ans;
        } else
          t += (2 * (i - last)) + 1;
        last = 2000000000;
      } else
        t++;
    } else
      t++;
  }
  return ans;
}
int main() {
  cin >> n >> t;
  cin >> s;
  casas = 0;
  ult = -1;
  for (int i = 0; i < n; i++)
    if (s[i] == 'H') casas++, ult = max(ult, i);
  int ini = 0, fim = casas;
  if (solve(fim) > t) {
    printf("-1\n");
    return 0;
  }
  while (ini < fim) {
    int mid = (ini + fim) / 2;
    if (solve(mid) <= t)
      fim = mid;
    else
      ini = mid + 1;
  }
  cout << ini << endl;
  return 0;
}
