#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int fin;
bool chk(int cnd) {
  int cnt = 0;
  int cnt2 = 0;
  int h = 0;
  for (int i = 0; i < n; i++) {
    cnt2 = min(cnt2, cnt) + 2;
    if (cnd >= h)
      cnt++;
    else
      cnt += 3;
    if (s[i] == 'S') cnd++;
    if (s[i] == 'H') h++;
    if (i >= fin && cnd >= h) break;
  }
  if (cnd < h) return 0;
  return min(cnt2, cnt) <= t;
}
int main() {
  scanf("%d%d", &n, &t);
  cin >> s;
  int x;
  for (int i = 0; i < n; i++)
    if (s[i] == 'H') fin = i;
  long long lo = 0, hi = n;
  while (lo < hi) {
    int md = lo + (hi - lo) / 2;
    if (chk(md))
      hi = md;
    else
      lo = md + 1;
  }
  if (!chk(lo)) return 0 * puts("-1");
  cout << lo << '\n';
  return 0;
}
